[PATCH] Fix memory leak in scdaemon

Werner Koch wk at gnupg.org
Sun Oct 25 16:11:29 CET 2009


On Sat, 24 Oct 2009 18:49, klaus at flittner.org said:

> in scd/command.c the buffer allocated by cmd_setdata is never freed.
> The attached patch frees the buffer after use and before a second use
> of setdata.

Good catch.  The fix is eaven easier than yours; see below.


Shalom-Salam,

   Werner


Index: scd/command.c
===================================================================
--- scd/command.c       (revision 5172)
+++ scd/command.c       (working copy)
@@ -804,6 +804,7 @@
   if (!buf)
     return out_of_core ();
 
+  xfree (ctrl->in_data.value);
   ctrl->in_data.value = buf;
   ctrl->in_data.valuelen = n;
   for (p=line, n=0; n < ctrl->in_data.valuelen; p += 2, n++)
Index: scd/scdaemon.c
===================================================================
--- scd/scdaemon.c      (revision 5172)
+++ scd/scdaemon.c      (working copy)
@@ -892,7 +892,11 @@
 static void
 scd_deinit_default_ctrl (ctrl_t ctrl)
 {
-  (void)ctrl;
+  if (!ctrl)
+    return;
+  xfree (ctrl->in_data.value);
+  ctrl->in_data.value = NULL;
+  ctrl->in_data.valuelen = 0;
 }
 

-- 
Die Gedanken sind frei.  Auschnahme regelt ein Bundeschgesetz.




More information about the Gnupg-devel mailing list