Fixing double unreferencing of key in pgp_gpg.c
authorEdouard Tisserant
Tue, 24 May 2016 11:26:24 +0200
changeset 6770fe0f82eb621
parent 676 aa02f6473007
child 678 f8181e59ae2f
Fixing double unreferencing of key in pgp_gpg.c
src/pgp_gpg.c
     1.1 --- a/src/pgp_gpg.c	Mon May 23 02:37:17 2016 +0200
     1.2 +++ b/src/pgp_gpg.c	Tue May 24 11:26:24 2016 +0200
     1.3 @@ -476,28 +476,22 @@
     1.4                                  && key->subkeys->fpr[0])
     1.5                              {
     1.6                                  k = stringlist_add(k, key->subkeys->fpr);
     1.7 +
     1.8                                  gpg.gpgme_key_unref(key);
     1.9 -                            }
    1.10 -                            else if(gpgme_error == GPG_ERR_NOT_OPERATIONAL)
    1.11 -                            {
    1.12 -                                // With some gpgme version, gpgme_get_key fail
    1.13 -                                // with GPG_ERR_NOT_OPERATIONAL, but in that
    1.14 -                                // case fpr is the primary one...
    1.15 -                                k = stringlist_add(k, gpgme_signature->fpr);
    1.16 +
    1.17 +                                if (k == NULL) {
    1.18 +                                    free_stringlist(_keylist);
    1.19 +                                    gpg.gpgme_data_release(plain);
    1.20 +                                    gpg.gpgme_data_release(cipher);
    1.21 +                                    free(_buffer);
    1.22 +                                    return PEP_OUT_OF_MEMORY;
    1.23 +                                }
    1.24                              }
    1.25                              else 
    1.26                              {
    1.27                                  result = PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH;
    1.28                                  break;
    1.29                              }
    1.30 -                            if (k == NULL) {
    1.31 -                                free_stringlist(_keylist);
    1.32 -                                gpg.gpgme_data_release(plain);
    1.33 -                                gpg.gpgme_data_release(cipher);
    1.34 -                                free(_buffer);
    1.35 -                                return PEP_OUT_OF_MEMORY;
    1.36 -                            }
    1.37 -
    1.38                              break;
    1.39                          }
    1.40                          case GPG_ERR_CERT_REVOKED:
    1.41 @@ -679,27 +673,20 @@
    1.42                      && key->subkeys->fpr[0])
    1.43                  {
    1.44                      k = stringlist_add(k, key->subkeys->fpr);
    1.45 +
    1.46                      gpg.gpgme_key_unref(key);
    1.47 -                }
    1.48 -                else if(gpgme_error == GPG_ERR_NOT_OPERATIONAL)
    1.49 -                {
    1.50 -                    // With some gpgme version, gpgme_get_key fail
    1.51 -                    // with GPG_ERR_NOT_OPERATIONAL, but in that
    1.52 -                    // case fpr is the primary one...
    1.53 -                    k = stringlist_add(k, gpgme_signature->fpr);
    1.54 +
    1.55 +                    if (k == NULL) {
    1.56 +                        free_stringlist(_keylist);
    1.57 +                        gpg.gpgme_data_release(d_text);
    1.58 +                        gpg.gpgme_data_release(d_sig);
    1.59 +                        return PEP_OUT_OF_MEMORY;
    1.60 +                    }
    1.61                  }
    1.62                  else {
    1.63                      result = PEP_DECRYPT_SIGNATURE_DOES_NOT_MATCH;
    1.64                      break;
    1.65                  }
    1.66 -                if (k == NULL) {
    1.67 -                    free_stringlist(_keylist);
    1.68 -                    gpg.gpgme_data_release(d_text);
    1.69 -                    gpg.gpgme_data_release(d_sig);
    1.70 -                    return PEP_OUT_OF_MEMORY;
    1.71 -                }
    1.72 -
    1.73 -                gpg.gpgme_key_unref(key);
    1.74  
    1.75                  if (gpgme_signature->summary & GPGME_SIGSUM_RED) {
    1.76                      if (gpgme_signature->summary & GPGME_SIGSUM_KEY_EXPIRED