Fix memory leak and uninitialised variables in case of error
authorKrista Bennett <krista@pep-project.org>
Mon, 16 Apr 2018 15:26:43 +0200
changeset 2608c04e5c003995
parent 2604 a1288e25cc9d
child 2609 83d11374a328
Fix memory leak and uninitialised variables in case of error
src/message_api.c
     1.1 --- a/src/message_api.c	Mon Apr 16 12:45:09 2018 +0200
     1.2 +++ b/src/message_api.c	Mon Apr 16 15:26:43 2018 +0200
     1.3 @@ -1849,6 +1849,11 @@
     1.4      char* own_id = NULL;
     1.5      char* default_id = NULL;
     1.6      
     1.7 +    pEp_identity* own_identity = NULL;
     1.8 +    char* own_private_fpr = NULL;
     1.9 +
    1.10 +    char* priv_key_data = NULL;
    1.11 +    
    1.12      PEP_STATUS status = get_default_own_userid(session, &own_id);
    1.13      
    1.14      if (!own_id)
    1.15 @@ -1867,14 +1872,14 @@
    1.16      // Ok, we are at least marginally sure the initial stuff is ok.
    1.17          
    1.18      // Let's get our own, normal identity
    1.19 -    pEp_identity* own_identity = identity_dup(src->from);
    1.20 +    own_identity = identity_dup(src->from);
    1.21      status = myself(session, own_identity);
    1.22  
    1.23      if (status != PEP_STATUS_OK)
    1.24          goto pep_free;
    1.25  
    1.26      // Ok, now we know the address is an own address. All good. Then...
    1.27 -    char* own_private_fpr = own_identity->fpr;
    1.28 +    own_private_fpr = own_identity->fpr;
    1.29      own_identity->fpr = strdup(to_fpr);
    1.30      
    1.31      status = get_trust(session, own_identity);
    1.32 @@ -1892,7 +1897,6 @@
    1.33                  
    1.34      // Ok, so all the things are now allowed.
    1.35      // So let's get our own private key and roll with it.
    1.36 -    char* priv_key_data = NULL;
    1.37      size_t priv_key_size = 0;
    1.38      
    1.39      status = export_secret_key(session, own_private_fpr, &priv_key_data, 
    1.40 @@ -1981,6 +1985,7 @@
    1.41      free(own_id);
    1.42      free(default_id);
    1.43      free(own_private_fpr);
    1.44 +    free(priv_key_data);
    1.45      free_identity(own_identity);
    1.46      free_stringlist(keys);
    1.47      return status;
    1.48 @@ -3203,7 +3208,6 @@
    1.49                  *flags |= PEP_decrypt_flag_own_private_key;
    1.50              }
    1.51          }
    1.52 -        
    1.53      }
    1.54  
    1.55      // 2. Clean up message and prepare for return