Fixed some warning, probably caused by NDEBUG being defined. Fixed some possible memory leak in map_asn1.c
authorEdouard Tisserant <edouard@pep-project.org>
Wed, 15 Mar 2017 16:42:58 +0100
changeset 16708e2509f0ddad
parent 1666 01779e4c5940
child 1674 5639f969866a
Fixed some warning, probably caused by NDEBUG being defined. Fixed some possible memory leak in map_asn1.c
src/map_asn1.c
src/pEpEngine.c
     1.1 --- a/src/map_asn1.c	Mon Mar 13 22:44:12 2017 +0100
     1.2 +++ b/src/map_asn1.c	Wed Mar 15 16:42:58 2017 +0100
     1.3 @@ -9,12 +9,15 @@
     1.4          Identity_t *result
     1.5      )
     1.6  {
     1.7 +    bool allocated = !result;
     1.8 +
     1.9      assert(ident);
    1.10      if (!ident)
    1.11          return NULL;
    1.12  
    1.13 -    if (!result)
    1.14 +    if (allocated){
    1.15          result = (Identity_t *) calloc(1, sizeof(Identity_t));
    1.16 +    }
    1.17      assert(result);
    1.18      if (!result)
    1.19          return NULL;
    1.20 @@ -56,26 +59,34 @@
    1.21      if (ident->lang[0]) {
    1.22          int r = OCTET_STRING_fromBuf(&result->lang, ident->lang, 2);
    1.23          assert(r == 0);
    1.24 +        if(r != 0)
    1.25 +            goto enomem;
    1.26      }
    1.27      else {
    1.28          int r = OCTET_STRING_fromBuf(&result->lang, "en", 2);
    1.29          assert(r == 0);
    1.30 +        if(r != 0)
    1.31 +            goto enomem;
    1.32      }
    1.33  
    1.34      return result;
    1.35  
    1.36  enomem:
    1.37 -    ASN_STRUCT_FREE(asn_DEF_Identity, result);
    1.38 +    if (allocated){
    1.39 +        ASN_STRUCT_FREE(asn_DEF_Identity, result);
    1.40 +    }
    1.41      return NULL;
    1.42  }
    1.43  
    1.44  pEp_identity *Identity_to_Struct(Identity_t *ident, pEp_identity *result)
    1.45  {
    1.46 +    bool allocated = !result;
    1.47 +
    1.48      assert(ident);
    1.49      if (!ident)
    1.50          return NULL;
    1.51      
    1.52 -    if (!result)
    1.53 +    if (allocated)
    1.54          result = new_identity(NULL, NULL, NULL, NULL);
    1.55      if (!result)
    1.56          return NULL;
    1.57 @@ -121,7 +132,8 @@
    1.58      return result;
    1.59  
    1.60  enomem:
    1.61 -    free_identity(result);
    1.62 +    if (allocated)
    1.63 +        free_identity(result);
    1.64      return NULL;
    1.65  }
    1.66  
    1.67 @@ -130,11 +142,13 @@
    1.68          IdentityList_t *result
    1.69      )
    1.70  {
    1.71 +    bool allocated = !result;
    1.72 +
    1.73      assert(list);
    1.74      if (!list)
    1.75          return NULL;
    1.76  
    1.77 -    if (!result)
    1.78 +    if (allocated)
    1.79          result = (IdentityList_t *) calloc(1, sizeof(IdentityList_t));
    1.80      assert(result);
    1.81      if (!result)
    1.82 @@ -151,17 +165,20 @@
    1.83      return result;
    1.84  
    1.85  enomem:
    1.86 -    ASN_STRUCT_FREE(asn_DEF_IdentityList, result);
    1.87 +    if (allocated)
    1.88 +        ASN_STRUCT_FREE(asn_DEF_IdentityList, result);
    1.89      return NULL;
    1.90  }
    1.91  
    1.92  identity_list *IdentityList_to_identity_list(IdentityList_t *list, identity_list *result)
    1.93  {
    1.94 +    bool allocated = !result;
    1.95 +
    1.96      assert(list);
    1.97      if (!list)
    1.98          return NULL;
    1.99  
   1.100 -    if (!result)
   1.101 +    if (allocated)
   1.102          result = new_identity_list(NULL);
   1.103      if (!result)
   1.104          return NULL;
   1.105 @@ -177,7 +194,8 @@
   1.106      return result;
   1.107  
   1.108  enomem:
   1.109 -    free_identity_list(result);
   1.110 +    if (allocated)
   1.111 +        free_identity_list(result);
   1.112      return NULL;
   1.113  }
   1.114  
     2.1 --- a/src/pEpEngine.c	Mon Mar 13 22:44:12 2017 +0100
     2.2 +++ b/src/pEpEngine.c	Wed Mar 15 16:42:58 2017 +0100
     2.3 @@ -2267,5 +2267,8 @@
     2.4      );
     2.5      assert(int_result == SQLITE_OK);
     2.6  
     2.7 +    if (int_result != SQLITE_OK)
     2.8 +        return PEP_UNKNOWN_ERROR;
     2.9 +
    2.10      return PEP_STATUS_OK;
    2.11  }