diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-09-15 10:27:39 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-09-15 10:27:39 +0200 |
commit | fc19601efc46cf31bf81c0d5980d6802148f5964 (patch) | |
tree | 5f61135b55d83480db7e0d070361c6a913495c5e | |
parent | 4cc86b52d215b1d56368403ab0faccd92f701336 (diff) | |
download | exchange-fc19601efc46cf31bf81c0d5980d6802148f5964.tar.gz exchange-fc19601efc46cf31bf81c0d5980d6802148f5964.zip |
fix memory leaks in test case
-rwxr-xr-x | contrib/uncrustify-mode.el | 2 | ||||
-rw-r--r-- | src/bank-lib/test_bank_api.c | 57 | ||||
-rw-r--r-- | src/bank-lib/testing_api_helpers.c | 50 | ||||
-rw-r--r-- | src/include/taler_testing_bank_lib.h | 3 |
4 files changed, 69 insertions, 43 deletions
diff --git a/contrib/uncrustify-mode.el b/contrib/uncrustify-mode.el index 97118c06c..83868c6a1 100755 --- a/contrib/uncrustify-mode.el +++ b/contrib/uncrustify-mode.el | |||
@@ -23,7 +23,7 @@ | |||
23 | ;; drop requirements and this file into a directory in your `load-path', | 23 | ;; drop requirements and this file into a directory in your `load-path', |
24 | ;; and put these lines into your .emacs file. | 24 | ;; and put these lines into your .emacs file. |
25 | 25 | ||
26 | ;; (require 'uncrusfify-mode) | 26 | ;; (require 'uncrustify-mode) |
27 | ;; (add-hook 'c-mode-common-hook | 27 | ;; (add-hook 'c-mode-common-hook |
28 | ;; '(lambda () | 28 | ;; '(lambda () |
29 | ;; (uncrustify-mode 1))) | 29 | ;; (uncrustify-mode 1))) |
diff --git a/src/bank-lib/test_bank_api.c b/src/bank-lib/test_bank_api.c index 043234560..6ad47c825 100644 --- a/src/bank-lib/test_bank_api.c +++ b/src/bank-lib/test_bank_api.c | |||
@@ -1,21 +1,21 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of TALER | 2 | This file is part of TALER |
3 | Copyright (C) 2016, 2017 GNUnet e.V. | 3 | Copyright (C) 2016, 2017, 2019 GNUnet e.V. |
4 | 4 | ||
5 | TALER is free software; you can redistribute it and/or modify | 5 | TALER is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as | 6 | it under the terms of the GNU General Public License as |
7 | published by the Free Software Foundation; either version 3, | 7 | published by the Free Software Foundation; either version 3, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | TALER is distributed in the hope that it will be useful, | 10 | TALER is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty |
12 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | 12 | of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
13 | the GNU General Public License for more details. | 13 | the GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public | 15 | You should have received a copy of the GNU General Public |
16 | License along with TALER; see the file COPYING. If not, see | 16 | License along with TALER; see the file COPYING. If not, see |
17 | <http://www.gnu.org/licenses/> | 17 | <http://www.gnu.org/licenses/> |
18 | */ | 18 | */ |
19 | /** | 19 | /** |
20 | * @file bank/test_bank_api.c | 20 | * @file bank/test_bank_api.c |
21 | * @brief testcase to test bank's HTTP API interface | 21 | * @brief testcase to test bank's HTTP API interface |
@@ -156,15 +156,20 @@ main (int argc, | |||
156 | 156 | ||
157 | if (NULL == (dbconn = getenv ("TALER_EXCHANGEDB_POSTGRES_CONFIG"))) | 157 | if (NULL == (dbconn = getenv ("TALER_EXCHANGEDB_POSTGRES_CONFIG"))) |
158 | dbconn = defaultdb; | 158 | dbconn = defaultdb; |
159 | char *purgedb_cmd; | ||
160 | GNUNET_asprintf (&purgedb_cmd, | ||
161 | "taler-bank-manage -c bank.conf --with-db=%s django flush --no-input", | ||
162 | dbconn); | ||
163 | if (0 != system (purgedb_cmd)) | ||
164 | { | 159 | { |
165 | fprintf (stderr, | 160 | char *purgedb_cmd; |
166 | "Could not purge database\n"); | 161 | |
167 | return 77; | 162 | GNUNET_asprintf (&purgedb_cmd, |
163 | "taler-bank-manage -c bank.conf --with-db=%s django flush --no-input", | ||
164 | dbconn); | ||
165 | if (0 != system (purgedb_cmd)) | ||
166 | { | ||
167 | fprintf (stderr, | ||
168 | "Could not purge database\n"); | ||
169 | GNUNET_free (purgedb_cmd); | ||
170 | return 77; | ||
171 | } | ||
172 | GNUNET_free (purgedb_cmd); | ||
168 | } | 173 | } |
169 | 174 | ||
170 | bankd = GNUNET_OS_start_process (GNUNET_NO, | 175 | bankd = GNUNET_OS_start_process (GNUNET_NO, |
@@ -182,7 +187,7 @@ main (int argc, | |||
182 | { | 187 | { |
183 | fprintf (stderr, | 188 | fprintf (stderr, |
184 | "Failed to launch taler-bank-manage, skipping test\n"); | 189 | "Failed to launch taler-bank-manage, skipping test\n"); |
185 | return 77; /* report 'skip' */ | 190 | return 77; /* report 'skip' */ |
186 | } | 191 | } |
187 | /* give child time to start and bind against the socket */ | 192 | /* give child time to start and bind against the socket */ |
188 | fprintf (stderr, | 193 | fprintf (stderr, |
diff --git a/src/bank-lib/testing_api_helpers.c b/src/bank-lib/testing_api_helpers.c index 411391e5a..e2a980ec8 100644 --- a/src/bank-lib/testing_api_helpers.c +++ b/src/bank-lib/testing_api_helpers.c | |||
@@ -28,8 +28,15 @@ | |||
28 | #include "taler_testing_bank_lib.h" | 28 | #include "taler_testing_bank_lib.h" |
29 | #include "taler_fakebank_lib.h" | 29 | #include "taler_fakebank_lib.h" |
30 | 30 | ||
31 | /* Keep each bank account credentials at index: | 31 | |
32 | * bank account number - 1 */ | 32 | #define BANK_FAIL() \ |
33 | do {GNUNET_break (0); return NULL; } while (0) | ||
34 | |||
35 | |||
36 | /** | ||
37 | * Keep each bank account credentials at index: | ||
38 | * bank account number - 1 | ||
39 | */ | ||
33 | struct TALER_BANK_AuthenticationData AUTHS[] = { | 40 | struct TALER_BANK_AuthenticationData AUTHS[] = { |
34 | 41 | ||
35 | /* Bank credentials */ | 42 | /* Bank credentials */ |
@@ -97,7 +104,7 @@ TALER_TESTING_has_in_name (const char *prog_name, | |||
97 | size_t name_pos; | 104 | size_t name_pos; |
98 | size_t pos; | 105 | size_t pos; |
99 | 106 | ||
100 | if (!prog_name || !marker) | 107 | if (! prog_name || ! marker) |
101 | return GNUNET_NO; | 108 | return GNUNET_NO; |
102 | 109 | ||
103 | pos = 0; | 110 | pos = 0; |
@@ -110,7 +117,7 @@ TALER_TESTING_has_in_name (const char *prog_name, | |||
110 | } | 117 | } |
111 | if (name_pos == pos) | 118 | if (name_pos == pos) |
112 | return GNUNET_YES; | 119 | return GNUNET_YES; |
113 | return strstr(prog_name + name_pos, marker) != NULL; | 120 | return strstr (prog_name + name_pos, marker) != NULL; |
114 | } | 121 | } |
115 | 122 | ||
116 | /** | 123 | /** |
@@ -137,7 +144,6 @@ TALER_TESTING_run_bank (const char *config_filename, | |||
137 | char *serve_arg; | 144 | char *serve_arg; |
138 | struct GNUNET_CONFIGURATION_Handle *cfg; | 145 | struct GNUNET_CONFIGURATION_Handle *cfg; |
139 | 146 | ||
140 | |||
141 | cfg = GNUNET_CONFIGURATION_create (); | 147 | cfg = GNUNET_CONFIGURATION_create (); |
142 | if (GNUNET_OK != | 148 | if (GNUNET_OK != |
143 | GNUNET_CONFIGURATION_load (cfg, | 149 | GNUNET_CONFIGURATION_load (cfg, |
@@ -173,13 +179,15 @@ TALER_TESTING_run_bank (const char *config_filename, | |||
173 | "serve"); | 179 | "serve"); |
174 | GNUNET_break (0); | 180 | GNUNET_break (0); |
175 | GNUNET_CONFIGURATION_destroy (cfg); | 181 | GNUNET_CONFIGURATION_destroy (cfg); |
182 | GNUNET_free (database); | ||
176 | exit (77); | 183 | exit (77); |
177 | } | 184 | } |
185 | GNUNET_CONFIGURATION_destroy (cfg); | ||
178 | 186 | ||
179 | serve_arg = "serve-http"; | 187 | serve_arg = "serve-http"; |
180 | if (0 != strcmp ("http", serve_cfg)) | 188 | if (0 != strcmp ("http", serve_cfg)) |
181 | serve_arg = "serve-uwsgi"; | 189 | serve_arg = "serve-uwsgi"; |
182 | 190 | GNUNET_free (serve_cfg); | |
183 | bank_proc = GNUNET_OS_start_process | 191 | bank_proc = GNUNET_OS_start_process |
184 | (GNUNET_NO, | 192 | (GNUNET_NO, |
185 | GNUNET_OS_INHERIT_STD_ALL, | 193 | GNUNET_OS_INHERIT_STD_ALL, |
@@ -189,8 +197,11 @@ TALER_TESTING_run_bank (const char *config_filename, | |||
189 | "-c", config_filename, | 197 | "-c", config_filename, |
190 | "--with-db", database, | 198 | "--with-db", database, |
191 | serve_arg, NULL); | 199 | serve_arg, NULL); |
200 | GNUNET_free (database); | ||
192 | if (NULL == bank_proc) | 201 | if (NULL == bank_proc) |
202 | { | ||
193 | BANK_FAIL (); | 203 | BANK_FAIL (); |
204 | } | ||
194 | 205 | ||
195 | GNUNET_asprintf (&wget_cmd, | 206 | GNUNET_asprintf (&wget_cmd, |
196 | "wget -q -t 1 -T 1 %s" | 207 | "wget -q -t 1 -T 1 %s" |
@@ -212,6 +223,7 @@ TALER_TESTING_run_bank (const char *config_filename, | |||
212 | SIGTERM); | 223 | SIGTERM); |
213 | GNUNET_OS_process_wait (bank_proc); | 224 | GNUNET_OS_process_wait (bank_proc); |
214 | GNUNET_OS_process_destroy (bank_proc); | 225 | GNUNET_OS_process_destroy (bank_proc); |
226 | GNUNET_free (wget_cmd); | ||
215 | BANK_FAIL (); | 227 | BANK_FAIL (); |
216 | } | 228 | } |
217 | fprintf (stderr, "."); | 229 | fprintf (stderr, "."); |
@@ -219,6 +231,7 @@ TALER_TESTING_run_bank (const char *config_filename, | |||
219 | iter++; | 231 | iter++; |
220 | } | 232 | } |
221 | while (0 != system (wget_cmd)); | 233 | while (0 != system (wget_cmd)); |
234 | GNUNET_free (wget_cmd); | ||
222 | fprintf (stderr, "\n"); | 235 | fprintf (stderr, "\n"); |
223 | 236 | ||
224 | return bank_proc; | 237 | return bank_proc; |
@@ -248,12 +261,17 @@ TALER_TESTING_prepare_bank (const char *config_filename) | |||
248 | 261 | ||
249 | cfg = GNUNET_CONFIGURATION_create (); | 262 | cfg = GNUNET_CONFIGURATION_create (); |
250 | 263 | ||
251 | if (GNUNET_OK != GNUNET_CONFIGURATION_load | 264 | if (GNUNET_OK != |
252 | (cfg, config_filename)) | 265 | GNUNET_CONFIGURATION_load (cfg, config_filename)) |
266 | { | ||
267 | GNUNET_CONFIGURATION_destroy (cfg); | ||
253 | BANK_FAIL (); | 268 | BANK_FAIL (); |
254 | 269 | } | |
255 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string | 270 | if (GNUNET_OK != |
256 | (cfg, "bank", "DATABASE", &database)) | 271 | GNUNET_CONFIGURATION_get_value_string (cfg, |
272 | "bank", | ||
273 | "DATABASE", | ||
274 | &database)) | ||
257 | { | 275 | { |
258 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 276 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
259 | "bank", | 277 | "bank", |
@@ -262,13 +280,17 @@ TALER_TESTING_prepare_bank (const char *config_filename) | |||
262 | BANK_FAIL (); | 280 | BANK_FAIL (); |
263 | } | 281 | } |
264 | 282 | ||
265 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number | 283 | if (GNUNET_OK != |
266 | (cfg, "bank", "HTTP_PORT", &port)) | 284 | GNUNET_CONFIGURATION_get_value_number (cfg, |
285 | "bank", | ||
286 | "HTTP_PORT", | ||
287 | &port)) | ||
267 | { | 288 | { |
268 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 289 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
269 | "bank", | 290 | "bank", |
270 | "HTTP_PORT"); | 291 | "HTTP_PORT"); |
271 | GNUNET_CONFIGURATION_destroy (cfg); | 292 | GNUNET_CONFIGURATION_destroy (cfg); |
293 | GNUNET_free (database); | ||
272 | BANK_FAIL (); | 294 | BANK_FAIL (); |
273 | } | 295 | } |
274 | GNUNET_CONFIGURATION_destroy (cfg); | 296 | GNUNET_CONFIGURATION_destroy (cfg); |
@@ -298,8 +320,10 @@ TALER_TESTING_prepare_bank (const char *config_filename) | |||
298 | { | 320 | { |
299 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 321 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
300 | "Failed to flush the bank db.\n"); | 322 | "Failed to flush the bank db.\n"); |
323 | GNUNET_free (database); | ||
301 | BANK_FAIL (); | 324 | BANK_FAIL (); |
302 | } | 325 | } |
326 | GNUNET_free (database); | ||
303 | 327 | ||
304 | if (GNUNET_SYSERR == | 328 | if (GNUNET_SYSERR == |
305 | GNUNET_OS_process_wait_status (dbreset_proc, | 329 | GNUNET_OS_process_wait_status (dbreset_proc, |
diff --git a/src/include/taler_testing_bank_lib.h b/src/include/taler_testing_bank_lib.h index 535fd2e9c..1152c6297 100644 --- a/src/include/taler_testing_bank_lib.h +++ b/src/include/taler_testing_bank_lib.h | |||
@@ -48,9 +48,6 @@ | |||
48 | 48 | ||
49 | /* ********************* Helper functions ********************* */ | 49 | /* ********************* Helper functions ********************* */ |
50 | 50 | ||
51 | #define BANK_FAIL() \ | ||
52 | do {GNUNET_break (0); return NULL; } while (0) | ||
53 | |||
54 | /** | 51 | /** |
55 | * Start the (Python) bank process. Assume the port | 52 | * Start the (Python) bank process. Assume the port |
56 | * is available and the database is clean. Use the "prepare | 53 | * is available and the database is clean. Use the "prepare |