fixing key mode
authorvb
Mon, 26 Jan 2015 13:11:40 +0100
changeset 475ed7e8a4f0c2
parent 46 7471e31bb278
child 48 9ff5d2dfa75a
fixing key mode
src/pgp_gpg.c
     1.1 --- a/src/pgp_gpg.c	Sat Jan 24 15:26:40 2015 +0100
     1.2 +++ b/src/pgp_gpg.c	Mon Jan 26 13:11:40 2015 +0100
     1.3 @@ -976,15 +976,17 @@
     1.4          break;
     1.5      case GPG_ERR_INV_VALUE:
     1.6          assert(0);
     1.7 -        _switch_mode(session, GPGME_KEYLIST_MODE_EXTERN,
     1.8 -            GPGME_KEYLIST_MODE_LOCAL);
     1.9 +        _switch_mode(session, GPGME_KEYLIST_MODE_EXTERN, GPGME_KEYLIST_MODE_LOCAL);
    1.10          return PEP_UNKNOWN_ERROR;
    1.11      default:
    1.12 -        _switch_mode(session, GPGME_KEYLIST_MODE_EXTERN,
    1.13 -            GPGME_KEYLIST_MODE_LOCAL);
    1.14 +        _switch_mode(session, GPGME_KEYLIST_MODE_EXTERN, GPGME_KEYLIST_MODE_LOCAL);
    1.15          return PEP_GET_KEY_FAILED;
    1.16      };
    1.17  
    1.18 +    gpgme_ctx_t import_ctx;
    1.19 +    gpgme_error = session->gpg.gpgme_new(&import_ctx);
    1.20 +    assert(gpgme_error == GPG_ERR_NO_ERROR);
    1.21 +
    1.22      do {
    1.23          gpgme_error = session->gpg.gpgme_op_keylist_next(session->ctx, &key);
    1.24          gpgme_error = _GPGERR(gpgme_error);
    1.25 @@ -1000,7 +1002,7 @@
    1.26              keys[0] = key;
    1.27              keys[1] = NULL;
    1.28  
    1.29 -            gpgme_error = session->gpg.gpgme_op_import_keys(session->ctx, keys);
    1.30 +            gpgme_error = session->gpg.gpgme_op_import_keys(import_ctx, keys);
    1.31              gpgme_error = _GPGERR(gpgme_error);
    1.32              session->gpg.gpgme_key_unref(key);
    1.33              assert(gpgme_error != GPG_ERR_INV_VALUE);
    1.34 @@ -1008,19 +1010,21 @@
    1.35          }
    1.36              break;
    1.37          case GPG_ERR_ENOMEM:
    1.38 -            _switch_mode(session, GPGME_KEYLIST_MODE_EXTERN,
    1.39 -                GPGME_KEYLIST_MODE_LOCAL);
    1.40              session->gpg.gpgme_op_keylist_end(session->ctx);
    1.41 +            session->gpg.gpgme_release(import_ctx);
    1.42 +            _switch_mode(session, GPGME_KEYLIST_MODE_EXTERN, GPGME_KEYLIST_MODE_LOCAL);
    1.43              return PEP_OUT_OF_MEMORY;
    1.44          default:
    1.45              session->gpg.gpgme_op_keylist_end(session->ctx);
    1.46 +            session->gpg.gpgme_release(import_ctx);
    1.47 +            _switch_mode(session, GPGME_KEYLIST_MODE_EXTERN, GPGME_KEYLIST_MODE_LOCAL);
    1.48              return PEP_UNKNOWN_ERROR;
    1.49          };
    1.50      } while (gpgme_error != GPG_ERR_EOF);
    1.51  
    1.52      session->gpg.gpgme_op_keylist_end(session->ctx);
    1.53 -    _switch_mode(session, GPGME_KEYLIST_MODE_EXTERN,
    1.54 -        GPGME_KEYLIST_MODE_LOCAL);
    1.55 +    session->gpg.gpgme_release(import_ctx);
    1.56 +    _switch_mode(session, GPGME_KEYLIST_MODE_EXTERN, GPGME_KEYLIST_MODE_LOCAL);
    1.57      return PEP_STATUS_OK;
    1.58  }
    1.59