fix memory leaks in test case

This commit is contained in:
Christian Grothoff 2019-09-15 10:27:39 +02:00
parent 4cc86b52d2
commit fc19601efc
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
4 changed files with 66 additions and 40 deletions

View File

@ -23,7 +23,7 @@
;; drop requirements and this file into a directory in your `load-path', ;; drop requirements and this file into a directory in your `load-path',
;; and put these lines into your .emacs file. ;; and put these lines into your .emacs file.
;; (require 'uncrusfify-mode) ;; (require 'uncrustify-mode)
;; (add-hook 'c-mode-common-hook ;; (add-hook 'c-mode-common-hook
;; '(lambda () ;; '(lambda ()
;; (uncrustify-mode 1))) ;; (uncrustify-mode 1)))

View File

@ -1,6 +1,6 @@
/* /*
This file is part of TALER This file is part of TALER
Copyright (C) 2016, 2017 GNUnet e.V. Copyright (C) 2016, 2017, 2019 GNUnet e.V.
TALER is free software; you can redistribute it and/or modify TALER is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as it under the terms of the GNU General Public License as
@ -15,7 +15,7 @@
You should have received a copy of the GNU General Public You should have received a copy of the GNU General Public
License along with TALER; see the file COPYING. If not, see License along with TALER; see the file COPYING. If not, see
<http://www.gnu.org/licenses/> <http://www.gnu.org/licenses/>
*/ */
/** /**
* @file bank/test_bank_api.c * @file bank/test_bank_api.c
* @brief testcase to test bank's HTTP API interface * @brief testcase to test bank's HTTP API interface
@ -156,7 +156,9 @@ main (int argc,
if (NULL == (dbconn = getenv ("TALER_EXCHANGEDB_POSTGRES_CONFIG"))) if (NULL == (dbconn = getenv ("TALER_EXCHANGEDB_POSTGRES_CONFIG")))
dbconn = defaultdb; dbconn = defaultdb;
{
char *purgedb_cmd; char *purgedb_cmd;
GNUNET_asprintf (&purgedb_cmd, GNUNET_asprintf (&purgedb_cmd,
"taler-bank-manage -c bank.conf --with-db=%s django flush --no-input", "taler-bank-manage -c bank.conf --with-db=%s django flush --no-input",
dbconn); dbconn);
@ -164,8 +166,11 @@ main (int argc,
{ {
fprintf (stderr, fprintf (stderr,
"Could not purge database\n"); "Could not purge database\n");
GNUNET_free (purgedb_cmd);
return 77; return 77;
} }
GNUNET_free (purgedb_cmd);
}
bankd = GNUNET_OS_start_process (GNUNET_NO, bankd = GNUNET_OS_start_process (GNUNET_NO,
GNUNET_OS_INHERIT_STD_ALL, GNUNET_OS_INHERIT_STD_ALL,

View File

@ -28,8 +28,15 @@
#include "taler_testing_bank_lib.h" #include "taler_testing_bank_lib.h"
#include "taler_fakebank_lib.h" #include "taler_fakebank_lib.h"
/* Keep each bank account credentials at index:
* bank account number - 1 */ #define BANK_FAIL() \
do {GNUNET_break (0); return NULL; } while (0)
/**
* Keep each bank account credentials at index:
* bank account number - 1
*/
struct TALER_BANK_AuthenticationData AUTHS[] = { struct TALER_BANK_AuthenticationData AUTHS[] = {
/* Bank credentials */ /* Bank credentials */
@ -97,7 +104,7 @@ TALER_TESTING_has_in_name (const char *prog_name,
size_t name_pos; size_t name_pos;
size_t pos; size_t pos;
if (!prog_name || !marker) if (! prog_name || ! marker)
return GNUNET_NO; return GNUNET_NO;
pos = 0; pos = 0;
@ -110,7 +117,7 @@ TALER_TESTING_has_in_name (const char *prog_name,
} }
if (name_pos == pos) if (name_pos == pos)
return GNUNET_YES; return GNUNET_YES;
return strstr(prog_name + name_pos, marker) != NULL; return strstr (prog_name + name_pos, marker) != NULL;
} }
/** /**
@ -137,7 +144,6 @@ TALER_TESTING_run_bank (const char *config_filename,
char *serve_arg; char *serve_arg;
struct GNUNET_CONFIGURATION_Handle *cfg; struct GNUNET_CONFIGURATION_Handle *cfg;
cfg = GNUNET_CONFIGURATION_create (); cfg = GNUNET_CONFIGURATION_create ();
if (GNUNET_OK != if (GNUNET_OK !=
GNUNET_CONFIGURATION_load (cfg, GNUNET_CONFIGURATION_load (cfg,
@ -173,13 +179,15 @@ TALER_TESTING_run_bank (const char *config_filename,
"serve"); "serve");
GNUNET_break (0); GNUNET_break (0);
GNUNET_CONFIGURATION_destroy (cfg); GNUNET_CONFIGURATION_destroy (cfg);
GNUNET_free (database);
exit (77); exit (77);
} }
GNUNET_CONFIGURATION_destroy (cfg);
serve_arg = "serve-http"; serve_arg = "serve-http";
if (0 != strcmp ("http", serve_cfg)) if (0 != strcmp ("http", serve_cfg))
serve_arg = "serve-uwsgi"; serve_arg = "serve-uwsgi";
GNUNET_free (serve_cfg);
bank_proc = GNUNET_OS_start_process bank_proc = GNUNET_OS_start_process
(GNUNET_NO, (GNUNET_NO,
GNUNET_OS_INHERIT_STD_ALL, GNUNET_OS_INHERIT_STD_ALL,
@ -189,8 +197,11 @@ TALER_TESTING_run_bank (const char *config_filename,
"-c", config_filename, "-c", config_filename,
"--with-db", database, "--with-db", database,
serve_arg, NULL); serve_arg, NULL);
GNUNET_free (database);
if (NULL == bank_proc) if (NULL == bank_proc)
{
BANK_FAIL (); BANK_FAIL ();
}
GNUNET_asprintf (&wget_cmd, GNUNET_asprintf (&wget_cmd,
"wget -q -t 1 -T 1 %s" "wget -q -t 1 -T 1 %s"
@ -212,6 +223,7 @@ TALER_TESTING_run_bank (const char *config_filename,
SIGTERM); SIGTERM);
GNUNET_OS_process_wait (bank_proc); GNUNET_OS_process_wait (bank_proc);
GNUNET_OS_process_destroy (bank_proc); GNUNET_OS_process_destroy (bank_proc);
GNUNET_free (wget_cmd);
BANK_FAIL (); BANK_FAIL ();
} }
fprintf (stderr, "."); fprintf (stderr, ".");
@ -219,6 +231,7 @@ TALER_TESTING_run_bank (const char *config_filename,
iter++; iter++;
} }
while (0 != system (wget_cmd)); while (0 != system (wget_cmd));
GNUNET_free (wget_cmd);
fprintf (stderr, "\n"); fprintf (stderr, "\n");
return bank_proc; return bank_proc;
@ -248,12 +261,17 @@ TALER_TESTING_prepare_bank (const char *config_filename)
cfg = GNUNET_CONFIGURATION_create (); cfg = GNUNET_CONFIGURATION_create ();
if (GNUNET_OK != GNUNET_CONFIGURATION_load if (GNUNET_OK !=
(cfg, config_filename)) GNUNET_CONFIGURATION_load (cfg, config_filename))
{
GNUNET_CONFIGURATION_destroy (cfg);
BANK_FAIL (); BANK_FAIL ();
}
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string if (GNUNET_OK !=
(cfg, "bank", "DATABASE", &database)) GNUNET_CONFIGURATION_get_value_string (cfg,
"bank",
"DATABASE",
&database))
{ {
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
"bank", "bank",
@ -262,13 +280,17 @@ TALER_TESTING_prepare_bank (const char *config_filename)
BANK_FAIL (); BANK_FAIL ();
} }
if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number if (GNUNET_OK !=
(cfg, "bank", "HTTP_PORT", &port)) GNUNET_CONFIGURATION_get_value_number (cfg,
"bank",
"HTTP_PORT",
&port))
{ {
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
"bank", "bank",
"HTTP_PORT"); "HTTP_PORT");
GNUNET_CONFIGURATION_destroy (cfg); GNUNET_CONFIGURATION_destroy (cfg);
GNUNET_free (database);
BANK_FAIL (); BANK_FAIL ();
} }
GNUNET_CONFIGURATION_destroy (cfg); GNUNET_CONFIGURATION_destroy (cfg);
@ -298,8 +320,10 @@ TALER_TESTING_prepare_bank (const char *config_filename)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to flush the bank db.\n"); "Failed to flush the bank db.\n");
GNUNET_free (database);
BANK_FAIL (); BANK_FAIL ();
} }
GNUNET_free (database);
if (GNUNET_SYSERR == if (GNUNET_SYSERR ==
GNUNET_OS_process_wait_status (dbreset_proc, GNUNET_OS_process_wait_status (dbreset_proc,

View File

@ -48,9 +48,6 @@
/* ********************* Helper functions ********************* */ /* ********************* Helper functions ********************* */
#define BANK_FAIL() \
do {GNUNET_break (0); return NULL; } while (0)
/** /**
* Start the (Python) bank process. Assume the port * Start the (Python) bank process. Assume the port
* is available and the database is clean. Use the "prepare * is available and the database is clean. Use the "prepare