memory leak in gpgme

Michael Schmidt mschmidt at cs.uni-sb.de
Fri Nov 9 09:56:01 CET 2001


Hi,

I think there is a memory leak in gpgme. I've played with a program
like this:

 gpgme_new (&my_ctx)

 for (i = 0; i < n; i++)
   {
     gpgme_data_new_from_mem (&in, d->data, d->data_length, 0);
     gpgme_data_new (&out);
     gpgme_op_decrypt (my_ctx, in, out)
     gpgme_data_release (in);
     decoded = gpgme_data_release_and_get_mem (out, &decoded_length);
     ...
     free (decoded);
   }

 gpgme_release (my_ctx);

I figured out, that there is a memory leak in the '_gpgme_gpg_release'
function: the argument list is not released. I wrote a small patch,
but someone familiar with the project should look at the data
arguments in 'arglist', since the "type check" to find deletable
data objects could be more elegant... :-)
-------------- next part --------------
--- rungpg.c	Mon Jul 30 14:35:58 2001
+++ rungpg.c.new	Thu Nov  8 22:02:04 2001
@@ -191,6 +191,7 @@
         rc = mk_error (Out_Of_Core);
         goto leave;
     }
+    gpg->arglist = NULL;
     gpg->argtail = &gpg->arglist;
 
     gpg->status.fd[0] = -1;
@@ -243,11 +244,26 @@
 }
 
 
+static void
+_gpgme_gpg_arglist_release ( struct arg_and_data_s *arglist )
+{
+    struct arg_and_data_s *n;
+
+    while (arglist) {
+        n = arglist->next;
+	if(arglist->data && arglist->data->type == GPGME_DATA_TYPE_CB)
+            gpgme_data_release (arglist->data);
+        xfree (arglist);
+        arglist = n;
+    }
+}
+
 void
 _gpgme_gpg_release ( GpgObject gpg )
 {
     if ( !gpg )
         return;
+    _gpgme_gpg_arglist_release (gpg->arglist);
     xfree (gpg->status.buffer);
     xfree (gpg->colon.buffer);
     if ( gpg->argv )
@@ -430,7 +446,7 @@
         if ( !gpg->pm.active ) {
             /* create the callback handler and connect it to stdin */
             GpgmeData tmp;
-            
+
             rc = gpgme_data_new_with_read_cb ( &tmp, pipemode_cb, gpg );
             if (!rc )
                 rc = _gpgme_gpg_add_data (gpg, tmp, 0);


More information about the Gnupg-devel mailing list