diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-09-15 10:54:10 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-09-15 10:54:10 +0200 |
commit | 8843d60e683157f40e1908a4dc57b82f6f6bb6ee (patch) | |
tree | 177c6bea47fb7580251aa9d3242f971d26970efe | |
parent | fc19601efc46cf31bf81c0d5980d6802148f5964 (diff) | |
download | exchange-8843d60e683157f40e1908a4dc57b82f6f6bb6ee.tar.gz exchange-8843d60e683157f40e1908a4dc57b82f6f6bb6ee.zip |
fix memory leak and style issues
-rw-r--r-- | src/exchange-tools/taler-wire.c | 70 | ||||
-rw-r--r-- | src/include/taler_wire_plugin.h | 50 | ||||
-rw-r--r-- | src/wire-plugins/plugin_wire_taler-bank.c | 22 | ||||
-rw-r--r-- | src/wire-plugins/test_wire_plugin_transactions_taler-bank.c | 7 |
4 files changed, 63 insertions, 86 deletions
diff --git a/src/exchange-tools/taler-wire.c b/src/exchange-tools/taler-wire.c index 213c1eff3..f9c4a3579 100644 --- a/src/exchange-tools/taler-wire.c +++ b/src/exchange-tools/taler-wire.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of TALER | 2 | This file is part of TALER |
3 | Copyright (C) 2014-2018 Taler Systems SA | 3 | Copyright (C) 2014--2019 Taler Systems SA |
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 |
@@ -29,62 +29,67 @@ | |||
29 | #include "taler_wire_lib.h" | 29 | #include "taler_wire_lib.h" |
30 | 30 | ||
31 | /** | 31 | /** |
32 | * If set to GNUNET_YES, then we'll ask the bank for a list | 32 | * If set to #GNUNET_YES, then we'll ask the bank for a list |
33 | * of transactions from the account mentioned in the config | 33 | * of transactions from the account mentioned in the config |
34 | * section. | 34 | * section. |
35 | */ | 35 | */ |
36 | int history; | 36 | static int history; |
37 | 37 | ||
38 | /** | 38 | /** |
39 | * If set to GNUNET_YES, then we'll ask the bank to execute a | 39 | * If set to GNUNET_YES, then we'll ask the bank to execute a |
40 | * wire transfer. | 40 | * wire transfer. |
41 | */ | 41 | */ |
42 | int transfer; | 42 | static int transfer; |
43 | 43 | ||
44 | /** | 44 | /** |
45 | * Name of the wire plugin to use with the bank. | 45 | * Name of the wire plugin to use with the bank. |
46 | */ | 46 | */ |
47 | char *plugin_name; | 47 | static char *plugin_name; |
48 | 48 | ||
49 | /** | 49 | /** |
50 | * Global return code. | 50 | * Global return code. |
51 | */ | 51 | */ |
52 | unsigned int global_ret = 1; | 52 | static unsigned int global_ret = 1; |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * When a wire transfer is being performed, this value | 55 | * When a wire transfer is being performed, this value |
56 | * specifies the amount to wire-transfer. It's given in | 56 | * specifies the amount to wire-transfer. It's given in |
57 | * the usual CURRENCY:X[.Y] format. | 57 | * the usual CURRENCY:X[.Y] format. |
58 | */ | 58 | */ |
59 | char *amount; | 59 | static char *amount; |
60 | 60 | ||
61 | /** | 61 | /** |
62 | * Base32 encoding of a transaction ID. When asking the | 62 | * Base32 encoding of a transaction ID. When asking the |
63 | * bank for a transaction history, all the results will | 63 | * bank for a transaction history, all the results will |
64 | * have a transaction ID settled *after* this one. | 64 | * have a transaction ID settled *after* this one. |
65 | */ | 65 | */ |
66 | char *since_when; | 66 | static char *since_when; |
67 | 67 | ||
68 | /** | 68 | /** |
69 | * Which config section has the credentials to access the bank. | 69 | * Which config section has the credentials to access the bank. |
70 | */ | 70 | */ |
71 | char *account_section; | 71 | static char *account_section; |
72 | 72 | ||
73 | /** | 73 | /** |
74 | * URL identifying the account that is going to receive the | 74 | * URL identifying the account that is going to receive the |
75 | * wire transfer. | 75 | * wire transfer. |
76 | */ | 76 | */ |
77 | char *destination_account_url; | 77 | static char *destination_account_url; |
78 | 78 | ||
79 | /** | 79 | /** |
80 | * Handle for the wire transfer preparation task. | 80 | * Handle for the wire transfer preparation task. |
81 | */ | 81 | */ |
82 | struct TALER_WIRE_PrepareHandle *ph; | 82 | static struct TALER_WIRE_PrepareHandle *ph; |
83 | 83 | ||
84 | /** | 84 | /** |
85 | * Wire plugin handle. | 85 | * Wire plugin handle. |
86 | */ | 86 | */ |
87 | struct TALER_WIRE_Plugin *plugin_handle; | 87 | static struct TALER_WIRE_Plugin *plugin_handle; |
88 | |||
89 | /** | ||
90 | * Handle to ongoing history operation. | ||
91 | */ | ||
92 | static struct TALER_WIRE_HistoryHandle *hh; | ||
88 | 93 | ||
89 | 94 | ||
90 | /** | 95 | /** |
@@ -274,15 +279,14 @@ execute_history () | |||
274 | bin_len)); | 279 | bin_len)); |
275 | } | 280 | } |
276 | 281 | ||
277 | if (NULL == plugin_handle->get_history | 282 | if (NULL == (hh = plugin_handle->get_history (plugin_handle->cls, |
278 | (plugin_handle->cls, | 283 | account_section, |
279 | account_section, | 284 | TALER_BANK_DIRECTION_BOTH, |
280 | TALER_BANK_DIRECTION_BOTH, | 285 | since_when_bin, |
281 | since_when_bin, | 286 | bin_len, |
282 | bin_len, | 287 | -10, |
283 | -10, | 288 | &history_cb, |
284 | history_cb, | 289 | NULL))) |
285 | NULL)) | ||
286 | { | 290 | { |
287 | fprintf (stderr, | 291 | fprintf (stderr, |
288 | "Could not request the transaction history.\n"); | 292 | "Could not request the transaction history.\n"); |
@@ -297,9 +301,21 @@ execute_history () | |||
297 | * | 301 | * |
298 | * @param cls closure. | 302 | * @param cls closure. |
299 | */ | 303 | */ |
300 | void | 304 | static void |
301 | do_shutdown (void *cls) | 305 | do_shutdown (void *cls) |
302 | { | 306 | { |
307 | if (NULL != hh) | ||
308 | { | ||
309 | plugin_handle->get_history_cancel (plugin_handle->cls, | ||
310 | hh); | ||
311 | hh = NULL; | ||
312 | } | ||
313 | if (NULL != ph) | ||
314 | { | ||
315 | plugin_handle->prepare_wire_transfer_cancel (plugin_handle->cls, | ||
316 | ph); | ||
317 | ph = NULL; | ||
318 | } | ||
303 | TALER_WIRE_plugin_unload (plugin_handle); | 319 | TALER_WIRE_plugin_unload (plugin_handle); |
304 | } | 320 | } |
305 | 321 | ||
@@ -377,8 +393,7 @@ main (int argc, | |||
377 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 393 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
378 | GNUNET_GETOPT_option_flag ('H', | 394 | GNUNET_GETOPT_option_flag ('H', |
379 | "history", | 395 | "history", |
380 | "Ask to get a list of 10" | 396 | "Ask to get a list of 10 transactions.", |
381 | " transactions.", | ||
382 | &history), | 397 | &history), |
383 | GNUNET_GETOPT_option_flag ('t', | 398 | GNUNET_GETOPT_option_flag ('t', |
384 | "transfer", | 399 | "transfer", |
@@ -398,9 +413,7 @@ main (int argc, | |||
398 | GNUNET_GETOPT_option_string ('s', | 413 | GNUNET_GETOPT_option_string ('s', |
399 | "section", | 414 | "section", |
400 | "ACCOUNT-SECTION", | 415 | "ACCOUNT-SECTION", |
401 | "Which config section has the" | 416 | "Which config section has the credentials to access the bank. Mandatory.\n", |
402 | " credentials to access the" | ||
403 | " bank. Mandatory.\n", | ||
404 | &account_section), | 417 | &account_section), |
405 | GNUNET_GETOPT_option_string ('a', | 418 | GNUNET_GETOPT_option_string ('a', |
406 | "amount", | 419 | "amount", |
@@ -410,8 +423,7 @@ main (int argc, | |||
410 | GNUNET_GETOPT_option_string ('d', | 423 | GNUNET_GETOPT_option_string ('d', |
411 | "destination", | 424 | "destination", |
412 | "PAYTO-URL", | 425 | "PAYTO-URL", |
413 | "Destination account for the" | 426 | "Destination account for the wire transfer.", |
414 | " wire transfer.", | ||
415 | &destination_account_url), | 427 | &destination_account_url), |
416 | GNUNET_GETOPT_OPTION_END | 428 | GNUNET_GETOPT_OPTION_END |
417 | }; | 429 | }; |
diff --git a/src/include/taler_wire_plugin.h b/src/include/taler_wire_plugin.h index eb43f2277..ffc7adf59 100644 --- a/src/include/taler_wire_plugin.h +++ b/src/include/taler_wire_plugin.h | |||
@@ -96,7 +96,8 @@ struct TALER_WIRE_TransferDetails | |||
96 | * | 96 | * |
97 | * @param cls closure | 97 | * @param cls closure |
98 | * @param ec taler error code | 98 | * @param ec taler error code |
99 | * @param dir direction of the transfer | 99 | * @param dir direction of the transfer, #TALER_BANK_DIRECTION_NONE when |
100 | * the iteration is complete | ||
100 | * @param row_off identification of the position at which we are querying | 101 | * @param row_off identification of the position at which we are querying |
101 | * @param row_off_size number of bytes in @a row_off | 102 | * @param row_off_size number of bytes in @a row_off |
102 | * @param details details about the wire transfer | 103 | * @param details details about the wire transfer |
@@ -368,53 +369,6 @@ struct TALER_WIRE_Plugin | |||
368 | (*reject_transfer_cancel)(void *cls, | 369 | (*reject_transfer_cancel)(void *cls, |
369 | struct TALER_WIRE_RejectHandle *rh); | 370 | struct TALER_WIRE_RejectHandle *rh); |
370 | 371 | ||
371 | |||
372 | /** | ||
373 | * Ask the plugin which data is needed to register the merchant | ||
374 | * into the banking institution. | ||
375 | * | ||
376 | * @param enc[out] where to store the JSON formatted list of | ||
377 | * needed values. The merchant will use this list to | ||
378 | * show a HTML form to the business in order to collect that data. | ||
379 | * This value will have to be freed by the caller. | ||
380 | * @param private_person GNUNET_OK if the merchant to be registered | ||
381 | * has a legal status of "person", for example they are freelance | ||
382 | * journalists. | ||
383 | * @param business GNUNET_OK if the merchant has the legal status | ||
384 | * of "business", so to say a "ordinary" shop. Cannot be | ||
385 | * both private and business though. | ||
386 | * @return GNUNET_OK upon successful `enc' allocation and definition, | ||
387 | * GNUNET_NO if _no_ data is needed at all, GNUNET_SYSERR | ||
388 | * for all the other cases. | ||
389 | */ | ||
390 | int | ||
391 | (*merchant_data)(char **out, | ||
392 | unsigned int private_person, | ||
393 | unsigned int business); | ||
394 | |||
395 | /** | ||
396 | * Send data to the banking institution in order to get the | ||
397 | * merchant registered. | ||
398 | * | ||
399 | * @param cls closure | ||
400 | * @param body subset of information to be sent to the bank. | ||
401 | * The plugin implementation is free to modify this value. | ||
402 | * @param mrcb Callback to process the outcome. | ||
403 | */ | ||
404 | struct TALER_WIRE_MerchantRegisterHandle * | ||
405 | (*merchant_register)(void *cls, | ||
406 | const char *body, | ||
407 | TALER_WIRE_MerchantRegisterCallback mrcb); | ||
408 | |||
409 | /** | ||
410 | * Cancel pending operation of merchant registering. | ||
411 | * | ||
412 | * @param cls closure | ||
413 | * @param mrh handle to the pending operation to be cancelled. | ||
414 | */ | ||
415 | void | ||
416 | (*merchant_register_cancel)(void *cls, | ||
417 | struct TALER_WIRE_MerchantRegisterHandle *mrh); | ||
418 | }; | 372 | }; |
419 | 373 | ||
420 | 374 | ||
diff --git a/src/wire-plugins/plugin_wire_taler-bank.c b/src/wire-plugins/plugin_wire_taler-bank.c index 97b1e6c84..e1db643d3 100644 --- a/src/wire-plugins/plugin_wire_taler-bank.c +++ b/src/wire-plugins/plugin_wire_taler-bank.c | |||
@@ -765,7 +765,8 @@ struct TALER_WIRE_HistoryHandle | |||
765 | { | 765 | { |
766 | 766 | ||
767 | /** | 767 | /** |
768 | * Function to call with results. | 768 | * Function to call with results, can become NULL if the |
769 | * application cancels the iteration. | ||
769 | */ | 770 | */ |
770 | TALER_WIRE_HistoryResultCallback hres_cb; | 771 | TALER_WIRE_HistoryResultCallback hres_cb; |
771 | 772 | ||
@@ -797,6 +798,7 @@ static void | |||
797 | taler_bank_get_history_cancel (void *cls, | 798 | taler_bank_get_history_cancel (void *cls, |
798 | struct TALER_WIRE_HistoryHandle *whh) | 799 | struct TALER_WIRE_HistoryHandle *whh) |
799 | { | 800 | { |
801 | (void) cls; | ||
800 | if (NULL != whh->hh) | 802 | if (NULL != whh->hh) |
801 | { | 803 | { |
802 | TALER_BANK_history_cancel (whh->hh); | 804 | TALER_BANK_history_cancel (whh->hh); |
@@ -893,7 +895,11 @@ bhist_cb (void *cls, | |||
893 | GNUNET_break (NULL != whh->hh); | 895 | GNUNET_break (NULL != whh->hh); |
894 | /* Once we get the sentinel element, the handle becomes invalid. */ | 896 | /* Once we get the sentinel element, the handle becomes invalid. */ |
895 | if (TALER_BANK_DIRECTION_NONE == dir) | 897 | if (TALER_BANK_DIRECTION_NONE == dir) |
898 | { | ||
896 | whh->hh = NULL; | 899 | whh->hh = NULL; |
900 | taler_bank_get_history_cancel (NULL, | ||
901 | whh); | ||
902 | } | ||
897 | return; | 903 | return; |
898 | } | 904 | } |
899 | case MHD_HTTP_NO_CONTENT: | 905 | case MHD_HTTP_NO_CONTENT: |
@@ -904,6 +910,9 @@ bhist_cb (void *cls, | |||
904 | NULL, | 910 | NULL, |
905 | 0, | 911 | 0, |
906 | NULL); | 912 | NULL); |
913 | whh->hh = NULL; | ||
914 | taler_bank_get_history_cancel (NULL, | ||
915 | whh); | ||
907 | break; | 916 | break; |
908 | default: | 917 | default: |
909 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 918 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -917,6 +926,9 @@ bhist_cb (void *cls, | |||
917 | NULL, | 926 | NULL, |
918 | 0, | 927 | 0, |
919 | NULL); | 928 | NULL); |
929 | whh->hh = NULL; | ||
930 | taler_bank_get_history_cancel (NULL, | ||
931 | whh); | ||
920 | break; | 932 | break; |
921 | } | 933 | } |
922 | whh->hh = NULL; | 934 | whh->hh = NULL; |
@@ -962,6 +974,7 @@ taler_bank_get_history (void *cls, | |||
962 | uint64_t start_row; | 974 | uint64_t start_row; |
963 | struct TALER_Account account; | 975 | struct TALER_Account account; |
964 | 976 | ||
977 | GNUNET_assert (NULL != hres_cb); | ||
965 | if (0 == num_results) | 978 | if (0 == num_results) |
966 | { | 979 | { |
967 | GNUNET_break (0); | 980 | GNUNET_break (0); |
@@ -1019,13 +1032,12 @@ taler_bank_get_history (void *cls, | |||
1019 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1032 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1020 | "Could not parse the auth values from '%s'\n", | 1033 | "Could not parse the auth values from '%s'\n", |
1021 | account_section); | 1034 | account_section); |
1035 | TALER_WIRE_account_free (&account); | ||
1022 | GNUNET_free (whh); | 1036 | GNUNET_free (whh); |
1023 | return NULL; | 1037 | return NULL; |
1024 | } | 1038 | } |
1025 | |||
1026 | whh->hres_cb = hres_cb; | 1039 | whh->hres_cb = hres_cb; |
1027 | whh->hres_cb_cls = hres_cb_cls; | 1040 | whh->hres_cb_cls = hres_cb_cls; |
1028 | |||
1029 | whh->hh = TALER_BANK_history (tc->ctx, | 1041 | whh->hh = TALER_BANK_history (tc->ctx, |
1030 | account.details.x_taler_bank.bank_base_url, | 1042 | account.details.x_taler_bank.bank_base_url, |
1031 | &whh->auth, | 1043 | &whh->auth, |
@@ -1040,16 +1052,16 @@ taler_bank_get_history (void *cls, | |||
1040 | if (NULL == whh->hh) | 1052 | if (NULL == whh->hh) |
1041 | { | 1053 | { |
1042 | GNUNET_break (0); | 1054 | GNUNET_break (0); |
1043 | taler_bank_get_history_cancel (NULL, | 1055 | taler_bank_get_history_cancel (tc, |
1044 | whh); | 1056 | whh); |
1045 | TALER_WIRE_account_free (&account); | 1057 | TALER_WIRE_account_free (&account); |
1046 | return NULL; | 1058 | return NULL; |
1047 | } | 1059 | } |
1048 | TALER_WIRE_account_free (&account); | 1060 | TALER_WIRE_account_free (&account); |
1049 | GNUNET_assert (NULL != whh); | ||
1050 | return whh; | 1061 | return whh; |
1051 | } | 1062 | } |
1052 | 1063 | ||
1064 | |||
1053 | /** | 1065 | /** |
1054 | * Context for a rejection operation. | 1066 | * Context for a rejection operation. |
1055 | */ | 1067 | */ |
diff --git a/src/wire-plugins/test_wire_plugin_transactions_taler-bank.c b/src/wire-plugins/test_wire_plugin_transactions_taler-bank.c index 2cda49a05..fa0db5b41 100644 --- a/src/wire-plugins/test_wire_plugin_transactions_taler-bank.c +++ b/src/wire-plugins/test_wire_plugin_transactions_taler-bank.c | |||
@@ -107,6 +107,7 @@ static struct TALER_WireTransferIdentifierRawP wtid; | |||
107 | static void | 107 | static void |
108 | do_shutdown (void *cls) | 108 | do_shutdown (void *cls) |
109 | { | 109 | { |
110 | (void) cls; | ||
110 | TALER_FAKEBANK_stop (fb); | 111 | TALER_FAKEBANK_stop (fb); |
111 | fb = NULL; | 112 | fb = NULL; |
112 | if (NULL != eh) | 113 | if (NULL != eh) |
@@ -186,11 +187,11 @@ history_result_cb | |||
186 | uint64_t serialh; | 187 | uint64_t serialh; |
187 | struct TALER_Amount amount; | 188 | struct TALER_Amount amount; |
188 | 189 | ||
189 | hh = NULL; | ||
190 | if ( (TALER_BANK_DIRECTION_NONE == dir) && | 190 | if ( (TALER_BANK_DIRECTION_NONE == dir) && |
191 | (GNUNET_OK == global_ret) ) | 191 | (GNUNET_OK == global_ret) ) |
192 | { | 192 | { |
193 | GNUNET_SCHEDULER_shutdown (); | 193 | GNUNET_SCHEDULER_shutdown (); |
194 | hh = NULL; | ||
194 | return GNUNET_OK; | 195 | return GNUNET_OK; |
195 | } | 196 | } |
196 | if (sizeof (uint64_t) != row_off_size) | 197 | if (sizeof (uint64_t) != row_off_size) |
@@ -251,6 +252,7 @@ confirmation_cb (void *cls, | |||
251 | const char *emsg) | 252 | const char *emsg) |
252 | { | 253 | { |
253 | uint64_t tmp; | 254 | uint64_t tmp; |
255 | |||
254 | eh = NULL; | 256 | eh = NULL; |
255 | if (GNUNET_OK != success) | 257 | if (GNUNET_OK != success) |
256 | { | 258 | { |
@@ -259,13 +261,10 @@ confirmation_cb (void *cls, | |||
259 | GNUNET_SCHEDULER_shutdown (); | 261 | GNUNET_SCHEDULER_shutdown (); |
260 | return; | 262 | return; |
261 | } | 263 | } |
262 | |||
263 | memcpy (&tmp, | 264 | memcpy (&tmp, |
264 | row_id, | 265 | row_id, |
265 | row_id_size); | 266 | row_id_size); |
266 | |||
267 | serial_target = GNUNET_ntohll (tmp); | 267 | serial_target = GNUNET_ntohll (tmp); |
268 | |||
269 | hh = plugin->get_history (plugin->cls, | 268 | hh = plugin->get_history (plugin->cls, |
270 | my_account, | 269 | my_account, |
271 | TALER_BANK_DIRECTION_BOTH, | 270 | TALER_BANK_DIRECTION_BOTH, |