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@g10code.com>
This commit is contained in:
Justus Winter 2016-06-28 18:13:40 +02:00
parent 6cb2be91a7
commit 9c67958c47
3 changed files with 32 additions and 14 deletions

View File

@ -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))

View File

@ -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;

View File

@ -282,5 +282,6 @@ main (int argc, char **argv)
}
scheme_deinit (sc);
xfree (sc);
return EXIT_SUCCESS;
}