From 9247e9081b6a2112e50a165ecff4403b5caa9f1f Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Mon, 25 Sep 2006 14:57:00 +0000 Subject: [PATCH] doc/ 2006-09-25 Marcus Brinkmann * gpgme.texi (Destroying Data Buffers): Clarify that gpgme_data_release_and_get_mem destroys DH unconditionally. gpgme/ 2006-09-25 Marcus Brinkmann * data-mem.c (gpgme_data_release_and_get_mem): Release the data object properly. --- NEWS | 2 ++ doc/ChangeLog | 5 +++++ doc/gpgme.texi | 3 ++- gpgme/ChangeLog | 5 +++++ gpgme/data-mem.c | 16 ++++++++++++++-- 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 05ed1039..f4f85c0e 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,8 @@ Noteworthy changes in version 1.1.3 (unreleased) ------------------------------------------------ + * Fixed a memory leak in gpgme_data_release_and_get_mem. + * Interface changes relative to the 1.1.1 release: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/doc/ChangeLog b/doc/ChangeLog index ebe0aa4a..759c2891 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,8 @@ +2006-09-25 Marcus Brinkmann + + * gpgme.texi (Destroying Data Buffers): Clarify that + gpgme_data_release_and_get_mem destroys DH unconditionally. + 2005-03-24 Marcus Brinkmann * gpgme.texi (Library Version Check): Make example code compatible diff --git a/doc/gpgme.texi b/doc/gpgme.texi index 5053645d..04deff31 100644 --- a/doc/gpgme.texi +++ b/doc/gpgme.texi @@ -1719,7 +1719,8 @@ the user provided the data buffer in non-copy mode, a copy will be made for this purpose. In case an error returns, or there is no suitable data buffer that can -be returned to the user, the function will return @code{NULL}. +be returned to the user, the function will return @code{NULL}. In any +case, the data object @var{dh} is destroyed. @end deftypefun diff --git a/gpgme/ChangeLog b/gpgme/ChangeLog index 63be9462..6f27890b 100644 --- a/gpgme/ChangeLog +++ b/gpgme/ChangeLog @@ -1,3 +1,8 @@ +2006-09-25 Marcus Brinkmann + + * data-mem.c (gpgme_data_release_and_get_mem): Release the data + object properly. + 2006-09-22 Marcus Brinkmann * keylist.c (keylist_colon_handler): Move debug output after diff --git a/gpgme/data-mem.c b/gpgme/data-mem.c index d0896deb..6e948ee0 100644 --- a/gpgme/data-mem.c +++ b/gpgme/data-mem.c @@ -210,20 +210,32 @@ gpgme_data_release_and_get_mem (gpgme_data_t dh, size_t *r_len) char *str = NULL; if (!dh || dh->cbs != &mem_cbs) - return NULL; + { + gpgme_data_release (dh); + return NULL; + } str = dh->data.mem.buffer; if (!str && dh->data.mem.orig_buffer) { str = malloc (dh->data.mem.length); if (!str) - return NULL; + { + gpgme_data_release (dh); + return NULL; + } memcpy (str, dh->data.mem.orig_buffer, dh->data.mem.length); } + else + /* Prevent mem_release from releasing the buffer memory. We must + not fail from this point. */ + dh->data.mem.buffer = NULL; if (r_len) *r_len = dh->data.mem.length; + gpgme_data_release (dh); + return str; }