[Pkg-gnupg-commit] [gnupg2] 68/160: gpgscm: Fix memory leaks.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Fri Jul 15 09:36:37 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch upstream
in repository gnupg2.

commit 9c67958c4737b34c60ef2076f57234eec155eb36
Author: Justus Winter <justus at g10code.com>
Date:   Tue Jun 28 18:13:40 2016 +0200

    gpgscm: Fix memory leaks.
    
    * tests/gpgscm/ffi-private.h (ffi_schemify_name): Fix prototype.
    (ffi_define_function_name): Free schemified name.
    (ffi_define_function): Likewise.
    (ffi_define_constant): Likewise.
    (ffi_define_variable_pointer): Likewise.
    * tests/gpgscm/ffi.c (do_wait_processes): Free arrays.
    (ffi_schemify_name): Fix type.
    * tests/gpgscm/main.c (main): Free 'sc'.
    
    Signed-off-by: Justus Winter <justus at g10code.com>
---
 tests/gpgscm/ffi-private.h | 40 +++++++++++++++++++++++++++-------------
 tests/gpgscm/ffi.c         |  5 ++++-
 tests/gpgscm/main.c        |  1 +
 3 files changed, 32 insertions(+), 14 deletions(-)

diff --git a/tests/gpgscm/ffi-private.h b/tests/gpgscm/ffi-private.h
index 849d1b7..87f491f 100644
--- a/tests/gpgscm/ffi-private.h
+++ b/tests/gpgscm/ffi-private.h
@@ -84,7 +84,7 @@ int ffi_bool_value (scheme *sc, pointer p);
 #define FFI_RETURN_STRING(SC, X)			\
   FFI_RETURN_POINTER ((SC), mk_string ((SC), (X)))
 
-const char *ffi_schemify_name (const char *s, int macro);
+char *ffi_schemify_name (const char *s, int macro);
 
 void ffi_scheme_eval (scheme *sc, const char *format, ...)
   GPGRT_ATTR_PRINTF (2, 3);
@@ -93,32 +93,46 @@ pointer ffi_sprintf (scheme *sc, const char *format, ...)
 
 #define ffi_define_function_name(SC, NAME, F)				\
   do {									\
+    char *_fname = ffi_schemify_name ("_" #F, 0);                        \
     scheme_define ((SC),						\
 		   (SC)->global_env,					\
-		   mk_symbol ((SC), ffi_schemify_name ("_" #F, 0)),	\
+		   mk_symbol ((SC), _fname),                            \
 		   mk_foreign_func ((SC), (do_##F)));			\
     ffi_scheme_eval ((SC),						\
 		     "(define (%s . a) (ffi-apply \"%s\" %s a))",	\
-		     (NAME), (NAME), ffi_schemify_name ("_" #F, 0));	\
+		     (NAME), (NAME), _fname);                           \
+    free (_fname);                                                      \
   } while (0)
 
-#define ffi_define_function(SC, F)				\
-  ffi_define_function_name ((SC), ffi_schemify_name (#F, 0), F)
+#define ffi_define_function(SC, F)                                      \
+  do {									\
+    char *_name = ffi_schemify_name (#F, 0);                            \
+    ffi_define_function_name ((SC), _name, F);                          \
+    free (_name);                                                       \
+  } while (0)
 
 #define ffi_define_constant(SC, C)					\
-  scheme_define ((SC),							\
-		 (SC)->global_env,					\
-		 mk_symbol ((SC), ffi_schemify_name (#C, 1)),		\
-		 mk_integer ((SC), (C)))
+  do {									\
+    char *_name = ffi_schemify_name (#C, 1);                            \
+    scheme_define ((SC),                                                \
+                   (SC)->global_env,					\
+                   mk_symbol ((SC), _name),                             \
+                   mk_integer ((SC), (C)));                             \
+    free (_name);                                                       \
+  } while (0)
 
 #define ffi_define(SC, SYM, EXP)					\
   scheme_define ((SC), (SC)->global_env, mk_symbol ((SC), (SYM)), EXP)
 
 #define ffi_define_variable_pointer(SC, C, P)				\
-  scheme_define ((SC),							\
-		 (SC)->global_env,					\
-		 mk_symbol ((SC), ffi_schemify_name (#C, 0)),		\
-		 (P))
+  do {									\
+    char *_name = ffi_schemify_name (#C, 0);                            \
+    scheme_define ((SC),                                                \
+                   (SC)->global_env,					\
+                   mk_symbol ((SC), _name),                             \
+                   (P));                                                \
+    free (_name);                                                       \
+  } while (0)
 
 #define ffi_define_variable_integer(SC, C)				\
   ffi_define_variable_pointer ((SC), C, (SC)->vptr->mk_integer ((SC), C))
diff --git a/tests/gpgscm/ffi.c b/tests/gpgscm/ffi.c
index dcdadaa..acfe1c7 100644
--- a/tests/gpgscm/ffi.c
+++ b/tests/gpgscm/ffi.c
@@ -776,6 +776,9 @@ do_wait_processes (scheme *sc, pointer args)
                                               (long) retcodes[count-1-i]),
                         retcodes_list);
 
+  xfree (names);
+  xfree (pids);
+  xfree (retcodes);
   FFI_RETURN_POINTER (sc, retcodes_list);
 }
 
@@ -1098,7 +1101,7 @@ ffi_list2intv (scheme *sc, pointer list, int **intv, size_t *len)
 }
 
 

-const char *
+char *
 ffi_schemify_name (const char *s, int macro)
 {
   char *n = strdup (s), *p;
diff --git a/tests/gpgscm/main.c b/tests/gpgscm/main.c
index 3414e3d..adb4e33 100644
--- a/tests/gpgscm/main.c
+++ b/tests/gpgscm/main.c
@@ -282,5 +282,6 @@ main (int argc, char **argv)
     }
 
   scheme_deinit (sc);
+  xfree (sc);
   return EXIT_SUCCESS;
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git



More information about the Pkg-gnupg-commit mailing list