diff --git a/lang/cpp/src/GpgmeppConfig.cmake.in.in b/lang/cpp/src/GpgmeppConfig.cmake.in.in index 3104d71..73f5eaa 100644 --- a/lang/cpp/src/GpgmeppConfig.cmake.in.in +++ b/lang/cpp/src/GpgmeppConfig.cmake.in.in @@ -63,7 +63,7 @@ add_library(Gpgmepp SHARED IMPORTED) set_target_properties(Gpgmepp PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "@resolved_includedir@/gpgme++;@resolved_includedir@" - INTERFACE_LINK_LIBRARIES "pthread;@resolved_libdir@/libgpgme@libsuffix@" + INTERFACE_LINK_LIBRARIES "pthread;@resolved_libdir@/libgpgme@libsuffix@;@LIBASSUAN_LIBS@" IMPORTED_LOCATION "@resolved_libdir@/libgpgmepp@libsuffix@" ) diff --git a/lang/cpp/src/context.cpp b/lang/cpp/src/context.cpp index e991dbc..c0a1dc2 100644 --- a/lang/cpp/src/context.cpp +++ b/lang/cpp/src/context.cpp @@ -223,7 +223,6 @@ Context *Context::createForProtocol(Protocol proto) } break; default: - gpgme_release(ctx); return nullptr; } @@ -274,7 +273,6 @@ std::unique_ptr Context::createForEngine(Engine eng, Error *error) } break; default: - gpgme_release(ctx); if (error) { *error = Error::fromCode(GPG_ERR_INV_ARG); } diff --git a/lang/cpp/src/data.cpp b/lang/cpp/src/data.cpp index d08a29d..7a93cbc 100644 --- a/lang/cpp/src/data.cpp +++ b/lang/cpp/src/data.cpp @@ -249,7 +249,6 @@ std::vector GpgME::Data::toKeys(Protocol proto) const } if (gpgme_op_keylist_from_data_start (ctx->impl()->ctx, d->data, 0)) { - delete ctx; return ret; } diff --git a/lang/python/gpgme.i b/lang/python/gpgme.i index 64b88d5..87371af 100644 --- a/lang/python/gpgme.i +++ b/lang/python/gpgme.i @@ -53,7 +53,7 @@ { encodedInput = PyUnicode_AsUTF8String($input); if (encodedInput == NULL) - SWIG_fail; + return NULL; $1 = PyBytes_AsString(encodedInput); } else if (PyBytes_Check($input)) @@ -62,25 +62,22 @@ PyErr_Format(PyExc_TypeError, "arg %d: expected str, bytes, or None, got %s", $argnum, $input->ob_type->tp_name); - SWIG_fail; + return NULL; } } %typemap(freearg) const char * { Py_XDECREF(encodedInput$argnum); } -%typemap(arginit) const char *[] { - $1 = NULL; -} - /* Likewise for a list of strings. */ -%typemap(in) const char *[] (size_t size, +%typemap(in) const char *[] (void *vector = NULL, + size_t size, PyObject **pyVector = NULL) { /* Check if is a list */ if (PyList_Check($input)) { size_t i, j; size = PyList_Size($input); - $1 = (char **) malloc((size+1) * sizeof(char *)); + $1 = (char **) (vector = malloc((size+1) * sizeof(char *))); pyVector = calloc(sizeof *pyVector, size); for (i = 0; i < size; i++) { @@ -89,7 +86,12 @@ { pyVector[i] = PyUnicode_AsUTF8String(o); if (pyVector[i] == NULL) - SWIG_fail; + { + free(vector); + for (j = 0; j < i; j++) + Py_XDECREF(pyVector[j]); + return NULL; + } $1[i] = PyBytes_AsString(pyVector[i]); } else if (PyString_Check(o)) @@ -99,7 +101,8 @@ "arg %d: list must contain only str or bytes, got %s " "at position %d", $argnum, o->ob_type->tp_name, i); - SWIG_fail; + free($1); + return NULL; } } $1[i] = NULL; @@ -107,17 +110,14 @@ PyErr_Format(PyExc_TypeError, "arg %d: expected a list of str or bytes, got %s", $argnum, $input->ob_type->tp_name); - SWIG_fail; + return NULL; } } %typemap(freearg) const char *[] { - if (pyVector$argnum) { - size_t i; - for (i = 0; i < size$argnum; i++) - Py_XDECREF(pyVector$argnum[i]); - free(pyVector$argnum); - } - if ($1) free($1); + size_t i; + free(vector$argnum); + for (i = 0; i < size$argnum; i++) + Py_XDECREF(pyVector$argnum[i]); } /* Release returned buffers as necessary. */ @@ -135,7 +135,7 @@ if (!PySequence_Check($input)) { PyErr_Format(PyExc_ValueError, "arg %d: Expected a list of gpgme_key_t", $argnum); - SWIG_fail; + return NULL; } if((numb = PySequence_Length($input)) != 0) { $1 = (gpgme_key_t*)malloc((numb+1)*sizeof(gpgme_key_t)); @@ -152,7 +152,8 @@ "arg %d: list must contain only gpgme_key_ts, got %s " "at position %d", $argnum, pypointer->ob_type->tp_name, i); - SWIG_fail; + free($1); + return NULL; } Py_DECREF(pypointer); } @@ -178,7 +179,7 @@ pypointer = _gpg_obj2gpgme_data_t($input, $argnum, &wrapper, &bytesio, &view); if (pypointer == NULL) - SWIG_fail; + return NULL; have_view = !! view.obj; /* input = $input, 1 = $1, 1_descriptor = $1_descriptor */ @@ -188,7 +189,7 @@ if ((SWIG_ConvertPtr(pypointer,(void **) &$1, $1_descriptor, SWIG_POINTER_EXCEPTION | $disown )) == -1) { Py_DECREF(pypointer); - SWIG_fail; + return NULL; } Py_DECREF(pypointer); } @@ -345,11 +346,6 @@ PyErr_SetString(PyExc_TypeError, "Numeric argument expected"); } -%typemap(arginit) (void *buffer, size_t size), (char *buf, size_t buflen) { - $1 = NULL; - $2 = 0; -} - /* Those are for gpgme_data_read() and gpgme_strerror_r(). */ %typemap(in) (void *buffer, size_t size), (char *buf, size_t buflen) { { @@ -363,12 +359,12 @@ else { PyErr_SetString(PyExc_TypeError, "Numeric argument expected"); - SWIG_fail; + return NULL; } if (tmp$argnum < 0) { PyErr_SetString(PyExc_ValueError, "Positive integer expected"); - SWIG_fail; + return NULL; } $2 = (size_t) tmp$argnum; $1 = ($1_ltype) malloc($2+1); @@ -377,11 +373,11 @@ %typemap(argout) (void *buffer, size_t size), (char *buf, size_t buflen) { Py_XDECREF($result); /* Blow away any previous result */ if (result < 0) { /* Check for I/O error */ - if ($1) free($1); + free($1); return PyErr_SetFromErrno(PyExc_RuntimeError); } $result = PyBytes_FromStringAndSize($1,result); - if ($1) free($1); + free($1); } /* For gpgme_data_write, but should be universal. */ @@ -394,11 +390,11 @@ { encodedInput = PyUnicode_AsUTF8String($input); if (encodedInput == NULL) - SWIG_fail; + return NULL; if (PyBytes_AsStringAndSize(encodedInput, (char **) &$1, &ssize) == -1) { Py_DECREF(encodedInput); - SWIG_fail; + return NULL; } } else if (PyBytes_Check($input)) @@ -407,7 +403,7 @@ PyErr_Format(PyExc_TypeError, "arg %d: expected str, bytes, or None, got %s", $argnum, $input->ob_type->tp_name); - SWIG_fail; + return NULL; } if (! $1) @@ -436,17 +432,8 @@ size++; } $result = PyList_New(size); - if ($result == NULL) - SWIG_fail; for (i=0,curr=$1; inext) { PyObject *o = SWIG_NewPointerObj(SWIG_as_voidptr(curr), $1_descriptor, %newpointer_flags); - if (o == NULL) { - int j; - for (j = 0; j < i; j++) - Py_XDECREF(PyList_GetItem($result, j)); - Py_DECREF($result); - SWIG_fail; - } PyList_SetItem($result, i, o); } } @@ -459,8 +446,6 @@ PyObject *fragile; fragile = SWIG_NewPointerObj(SWIG_as_voidptr($1), $1_descriptor, %newpointer_flags); - if (fragile == NULL) - SWIG_fail; $result = _gpg_wrap_result(fragile, name); Py_DECREF(fragile); } @@ -484,28 +469,22 @@ wrapresult(gpgme_vfs_mount_result_t, "VFSMountResult") } $result = PyList_New(size); if ($result == NULL) - SWIG_fail; /* raise */ + return NULL; /* raise */ for (i=0,curr=$1; inext) { PyObject *fragile, *o; fragile = SWIG_NewPointerObj(SWIG_as_voidptr(curr), $1_descriptor, %newpointer_flags); if (fragile == NULL) { - int j; - for (j = 0; j < i; j++) - Py_XDECREF(PyList_GetItem($result, j)); Py_DECREF($result); - SWIG_fail; /* raise */ + return NULL; /* raise */ } o = _gpg_wrap_result(fragile, "EngineInfo"); Py_DECREF(fragile); if (o == NULL) { - int j; - for (j = 0; j < i; j++) - Py_XDECREF(PyList_GetItem($result, j)); Py_DECREF($result); - SWIG_fail; /* raise */ + return NULL; /* raise */ } PyList_SetItem($result, i, o); } diff --git a/m4/ax_python_devel.m4 b/m4/ax_python_devel.m4 index e185284..55f0cff 100644 --- a/m4/ax_python_devel.m4 +++ b/m4/ax_python_devel.m4 @@ -137,7 +137,7 @@ variable to configure. See ``configure --help'' for reference. # AC_MSG_CHECKING([for the distutils Python package]) ac_distutils_result=`$PYTHON -c "import distutils" 2>&1` - if test $? -eq 0; then + if test -z "$ac_distutils_result"; then AC_MSG_RESULT([yes]) else AC_MSG_RESULT([no]) diff --git a/src/engine-gpg.c b/src/engine-gpg.c index 61c6fbb..dc2d945 100644 --- a/src/engine-gpg.c +++ b/src/engine-gpg.c @@ -1122,7 +1122,6 @@ build_argv (engine_gpg_t gpg, const char *pgmname) to avoid and given that we reach this here only after a malloc failure for a small object, it is probably better not to do anything. */ - free_argv (argv); return gpg_error (GPG_ERR_GENERAL); } /* If the data_type is FD, we have to do a dup2 here. */ @@ -1240,9 +1239,6 @@ read_status (engine_gpg_t gpg) buffer = realloc (buffer, bufsize); if (!buffer) return gpg_error_from_syserror (); - /* Update buffer and bufsize here to prevent memory leaks. */ - gpg->status.buffer = buffer; - gpg->status.bufsize = bufsize; } nread = _gpgme_io_read (gpg->status.fd[0], @@ -1355,6 +1351,8 @@ read_status (engine_gpg_t gpg) } /* Update the gpg object. */ + gpg->status.bufsize = bufsize; + gpg->status.buffer = buffer; gpg->status.readpos = readpos; return 0; } @@ -1394,9 +1392,6 @@ read_colon_line (engine_gpg_t gpg) buffer = realloc (buffer, bufsize); if (!buffer) return gpg_error_from_syserror (); - /* Prevent memory leaks. */ - gpg->colon.bufsize = bufsize; - gpg->colon.buffer = buffer; } nread = _gpgme_io_read (gpg->colon.fd[0], buffer+readpos, bufsize-readpos); @@ -1476,6 +1471,8 @@ read_colon_line (engine_gpg_t gpg) } /* Update the gpg object. */ + gpg->colon.bufsize = bufsize; + gpg->colon.buffer = buffer; gpg->colon.readpos = readpos; return 0; } @@ -2923,12 +2920,6 @@ gpg_keylist_build_options (engine_gpg_t gpg, int secret_only, err = add_arg (gpg, "--with-colons"); - if (have_gpg_version (gpg, "2.2.19")) - { - if (!err) - err = add_arg (gpg, "--with-keygrip"); - } - /* Since gpg 2.1.15 fingerprints are always printed, thus there is * no more need to explicitly request them. */ if (!have_gpg_version (gpg, "2.1.15")) diff --git a/src/engine-gpgsm.c b/src/engine-gpgsm.c index 1f603f1..ae5d8ef 100644 --- a/src/engine-gpgsm.c +++ b/src/engine-gpgsm.c @@ -1533,10 +1533,8 @@ gpgsm_export (void *engine, const char *pattern, gpgme_export_mode_t mode, gpgsm->output_cb.data = keydata; err = gpgsm_set_fd (gpgsm, OUTPUT_FD, use_armor ? "--armor" : map_data_enc (gpgsm->output_cb.data)); - if (err) { - free (cmd); + if (err) return err; - } gpgsm_clear_fd (gpgsm, INPUT_FD); gpgsm_clear_fd (gpgsm, MESSAGE_FD); gpgsm->inline_data = NULL; @@ -1636,10 +1634,8 @@ gpgsm_export_ext (void *engine, const char *pattern[], gpgme_export_mode_t mode, gpgsm->output_cb.data = keydata; err = gpgsm_set_fd (gpgsm, OUTPUT_FD, use_armor ? "--armor" : map_data_enc (gpgsm->output_cb.data)); - if (err) { - free (line); + if (err) return err; - } gpgsm_clear_fd (gpgsm, INPUT_FD); gpgsm_clear_fd (gpgsm, MESSAGE_FD); gpgsm->inline_data = NULL; diff --git a/src/engine.c b/src/engine.c index 7e2e380..05979c1 100644 --- a/src/engine.c +++ b/src/engine.c @@ -460,8 +460,7 @@ _gpgme_set_engine_info (gpgme_engine_info_t info, gpgme_protocol_t proto, if (!new_version) { free (new_file_name); - if (new_home_dir) - free (new_home_dir); + free (new_home_dir); return gpg_error_from_syserror (); } } diff --git a/src/gpgme-config.in b/src/gpgme-config.in index 7794923..56b98f8 100644 --- a/src/gpgme-config.in +++ b/src/gpgme-config.in @@ -25,12 +25,12 @@ cflags="-I@includedir@" libs="-L@libdir@" # Network libraries. -#assuan_cflags="@LIBASSUAN_CFLAGS@" -#assuan_libs="@LIBASSUAN_LIBS@" +assuan_cflags="@LIBASSUAN_CFLAGS@" +assuan_libs="@LIBASSUAN_LIBS@" # Configure libgpg-error. gpg_error_cflags="@GPG_ERROR_CFLAGS@" -#gpg_error_libs="@GPG_ERROR_LIBS@" +gpg_error_libs="@GPG_ERROR_LIBS@" # Configure thread packages. thread_modules="" @@ -48,10 +48,6 @@ libs_glib="@GLIB_LIBS@" cflags_glib="@GLIB_CFLAGS@" with_glib= -if test "0@NEED__FILE_OFFSET_BITS@" -gt "0" ; then - cflags_lfs="-D_FILE_OFFSET_BITS=@NEED__FILE_OFFSET_BITS@" -fi - output="" usage() @@ -115,9 +111,6 @@ while test $# -gt 0; do exit 0 ;; --cflags) - if test "x$cflags_lfs" != "x"; then - output="$output $cflags_lfs" - fi result= tmp_c= tmp_g= diff --git a/src/gpgme-tool.c b/src/gpgme-tool.c index f4ddd83..7a0bfcb 100644 --- a/src/gpgme-tool.c +++ b/src/gpgme-tool.c @@ -1189,7 +1189,6 @@ gt_get_key (gpgme_tool_t gt, const char *pattern, gpgme_key_t *r_key) similar hack to sort out such duplicates but it can't do that while listing keys. */ gpgme_key_unref (key); - key = NULL; goto try_next_key; } if (!err) diff --git a/src/keylist.c b/src/keylist.c index b7cbf3c..cdb115f 100644 --- a/src/keylist.c +++ b/src/keylist.c @@ -1321,7 +1321,6 @@ gpgme_get_key (gpgme_ctx_t ctx, const char *fpr, gpgme_key_t *r_key, similar hack to sort out such duplicates but it can't do that while listing keys. */ gpgme_key_unref (key); - key = NULL; goto try_next_key; } if (!err) diff --git a/tests/json/t-keylist-secret.out.json b/tests/json/t-keylist-secret.out.json index f997fd8..5da20db 100644 --- a/tests/json/t-keylist-secret.out.json +++ b/tests/json/t-keylist-secret.out.json @@ -91,6 +91,7 @@ "can_sign": true, "can_certify": true, "can_authenticate": true, + "secret": true, "is_qualified": false, "protocol": "OpenPGP", "fingerprint": "D695676BDCEDCC2CDD6152BCFE180B1DA9E3B0B2",