memory cleanup ENGINE-178
authorKrista Grothoff <krista@pep-project.org>
Mon, 20 Feb 2017 15:22:58 +0100
branchENGINE-178
changeset 1592cc35fb239fce
parent 1591 df20d8334b91
child 1593 37d5334bbb66
memory cleanup
src/pgp_gpg.c
     1.1 --- a/src/pgp_gpg.c	Mon Feb 20 15:15:14 2017 +0100
     1.2 +++ b/src/pgp_gpg.c	Mon Feb 20 15:22:58 2017 +0100
     1.3 @@ -462,8 +462,13 @@
     1.4                  gpgme_key_t key;
     1.5                  memset(&key,0,sizeof(key));
     1.6                  stringlist_t* recipient_keylist = new_stringlist(NULL);
     1.7 -                if (!recipient_keylist) // FIXME: mem cleanup
     1.8 +                if (!recipient_keylist) {
     1.9 +                    gpg.gpgme_data_release(plain);
    1.10 +                    gpg.gpgme_data_release(cipher);
    1.11 +                    if (recipient_keylist)
    1.12 +                        free_stringlist(recipient_keylist);
    1.13                      return PEP_OUT_OF_MEMORY;
    1.14 +                }
    1.15                 
    1.16                  if (gpgme_decrypt_result != NULL) {
    1.17                      stringlist_t* _keylist = recipient_keylist;
    1.18 @@ -702,45 +707,6 @@
    1.19          result = PEP_DECRYPT_WRONG_FORMAT;
    1.20      }
    1.21  
    1.22 -    // if (result != PEP_DECRYPT_WRONG_FORMAT && result != PEP_OUT_OF_MEMORY) {
    1.23 -    //     gpgme_key_t key;
    1.24 -    //     memset(&key,0,sizeof(key));
    1.25 -    //     
    1.26 -    //     if (gpgme_decrypt_result != NULL) {
    1.27 -    //         if (!(*keylist))
    1.28 -    //             *keylist = new_stringlist(""); // no sig
    1.29 -    //         stringlist_t* _keylist = *keylist;
    1.30 -    //         for (gpgme_recipient_t r = gpgme_decrypt_result->recipients; r != NULL; r = r->next) {
    1.31 -    //             // GPGME may give subkey's fpr instead of primary key's fpr.
    1.32 -    //             // Therefore we ask for the primary fingerprint instead
    1.33 -    //             // we assume that gpgme_get_key can find key by subkey's fpr
    1.34 -    //             gpgme_error = gpg.gpgme_get_key(session->ctx,
    1.35 -    //                 r->keyid, &key, 0);
    1.36 -    //             gpgme_error = _GPGERR(gpgme_error);
    1.37 -    //             assert(gpgme_error != GPG_ERR_ENOMEM);
    1.38 -    //             if (gpgme_error == GPG_ERR_ENOMEM) {
    1.39 -    //                 free_stringlist(_keylist);
    1.40 -    //                 result = PEP_OUT_OF_MEMORY;
    1.41 -    //             }
    1.42 -    //             // Primary key is given as the first subkey
    1.43 -    //             if (gpgme_error == GPG_ERR_NO_ERROR &&
    1.44 -    //                 key && key->subkeys && key->subkeys->fpr
    1.45 -    //                 && key->subkeys->fpr[0]) {
    1.46 -    //                 _keylist = stringlist_add(_keylist, key->subkeys->fpr);
    1.47 -    // 
    1.48 -    //                 gpg.gpgme_key_unref(key);
    1.49 -    // 
    1.50 -    //             }
    1.51 -    //         }
    1.52 -    //         assert(_keylist);
    1.53 -    //         if (_keylist == NULL) {
    1.54 -    //             free_stringlist(*keylist);
    1.55 -    //             *keylist = NULL;
    1.56 -    //             result = PEP_OUT_OF_MEMORY;
    1.57 -    //         }
    1.58 -    //     }
    1.59 -    //}
    1.60 -
    1.61      gpg.gpgme_data_release(plain);
    1.62      gpg.gpgme_data_release(cipher);
    1.63      return result;