From e46467510daf1dc55b9d01fcca42eb9912492133 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 19 Jan 2020 22:23:57 +0100 Subject: [PATCH] leak fixes --- src/benchmark/taler-exchange-benchmark.c | 64 +++++++++++++++---- src/exchange/test_taler_exchange_httpd_afl.sh | 13 ++-- src/lib/exchange_api_handle.c | 1 - src/testing/testing_api_cmd_withdraw.c | 24 +++---- 4 files changed, 70 insertions(+), 32 deletions(-) diff --git a/src/benchmark/taler-exchange-benchmark.c b/src/benchmark/taler-exchange-benchmark.c index 38ba810fa..bd4d3eafe 100644 --- a/src/benchmark/taler-exchange-benchmark.c +++ b/src/benchmark/taler-exchange-benchmark.c @@ -175,6 +175,21 @@ static char *remote_host; */ static char *remote_dir; +/** + * Array of command labels. + */ +static char **labels; + +/** + * Length of #labels. + */ +static unsigned int label_len; + +/** + * Offset in #labels. + */ +static unsigned int label_off; + /** * Don't kill exchange/fakebank/wirewatch until * requested by the user explicitly. @@ -182,8 +197,27 @@ static char *remote_dir; static int linger; +/** + * Add label to the #labels table and return it. + * + * @param label string to add to the table + * @return same string, now stored in the table + */ +const char * +add_label (char *label) +{ + if (label_off == label_len) + GNUNET_array_grow (labels, + label_len, + label_len * 2 + 4); + labels[label_off++] = label; + return label; +} + + static struct TALER_TESTING_Command -CMD_TRANSFER_TO_EXCHANGE (char *label, char *amount) +cmd_transfer_to_exchange (const char *label, + const char *amount) { return TALER_TESTING_cmd_admin_add_incoming_retry (TALER_TESTING_cmd_admin_add_incoming (label, @@ -283,9 +317,8 @@ run (void *cls, j); { struct TALER_TESTING_Command make_reserve[] = { - CMD_TRANSFER_TO_EXCHANGE (create_reserve_label, - TALER_amount_to_string - (&total_reserve_amount)), + cmd_transfer_to_exchange (add_label (create_reserve_label), + TALER_amount2s (&total_reserve_amount)), TALER_TESTING_cmd_end () }; char *batch_label; @@ -294,7 +327,7 @@ run (void *cls, "batch-start-%u", j); all_commands[j * (howmany_coins + 1)] - = TALER_TESTING_cmd_batch (batch_label, + = TALER_TESTING_cmd_batch (add_label (batch_label), make_reserve); } for (unsigned int i = 0; i < howmany_coins; i++) @@ -313,17 +346,17 @@ run (void *cls, i + (howmany_coins * j)); unit[0] = TALER_TESTING_cmd_withdraw_with_retry - (TALER_TESTING_cmd_withdraw_amount (withdraw_label, + (TALER_TESTING_cmd_withdraw_amount (add_label (withdraw_label), create_reserve_label, amount_5, MHD_HTTP_OK)); unit[1] = TALER_TESTING_cmd_deposit_with_retry (TALER_TESTING_cmd_deposit ("deposit", - withdraw_label, + add_label (withdraw_label), 0, /* Index of the one withdrawn coin in the traits. */ user_payto_uri, - order_enc, + add_label (order_enc), GNUNET_TIME_UNIT_ZERO, amount_1, MHD_HTTP_OK)); @@ -341,16 +374,16 @@ run (void *cls, i, j); unit[2] = - TALER_TESTING_cmd_refresh_melt_with_retry ( - TALER_TESTING_cmd_refresh_melt - (melt_label, + TALER_TESTING_cmd_refresh_melt_with_retry + (TALER_TESTING_cmd_refresh_melt + (add_label (melt_label), withdraw_label, MHD_HTTP_OK, NULL)); unit[3] = TALER_TESTING_cmd_refresh_reveal_with_retry (TALER_TESTING_cmd_refresh_reveal - (reveal_label, + (add_label (reveal_label), melt_label, MHD_HTTP_OK)); unit[4] = @@ -369,7 +402,7 @@ run (void *cls, i, j); all_commands[j * (howmany_coins + 1) + (1 + i)] - = TALER_TESTING_cmd_batch (unit_label, + = TALER_TESTING_cmd_batch (add_label (unit_label), unit); } } @@ -962,5 +995,10 @@ main (int argc, (unsigned long long) (usage.ru_utime.tv_sec * 1000 * 1000 + usage.ru_utime.tv_usec)); } + for (unsigned int i = 0; i /dev/null || true +taler-exchange-dbinit -c test_taler_exchange_httpd.conf &> /dev/null # Only log hard errors, we expect lots of warnings... export GNUNET_FORCE_LOG="taler-exchange-httpd;;;;ERROR/libmicrohttpd;;;;ERROR/util;;;;ERROR/" # Run test... for n in afl-tests/* do echo -n "Test $n " - $PREFIX taler-exchange-httpd -d test-exchange-home/ -t 1 -f $n -C > /dev/null || { echo "FAIL!"; } -# $PREFIX taler-exchange-httpd -d test-exchange-home/ -t 1 -f $n -C > /dev/null || { echo "FAIL!"; exit 1; } + $PREFIX taler-exchange-httpd -c test_taler_exchange_httpd.conf -t 1 -f $n -C > /dev/null || { echo "FAIL!"; } echo "OK" done exit 0 diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c index 33e9681f1..783cddea2 100644 --- a/src/lib/exchange_api_handle.c +++ b/src/lib/exchange_api_handle.c @@ -2156,7 +2156,6 @@ TALER_EXCHANGE_destroy_denomination_key (struct TALER_EXCHANGE_DenomPublicKey *key) { GNUNET_CRYPTO_rsa_public_key_free (key->key.rsa_public_key);; - key->key.rsa_public_key = NULL; GNUNET_free (key); } diff --git a/src/testing/testing_api_cmd_withdraw.c b/src/testing/testing_api_cmd_withdraw.c index b62420557..207d11876 100644 --- a/src/testing/testing_api_cmd_withdraw.c +++ b/src/testing/testing_api_cmd_withdraw.c @@ -263,23 +263,23 @@ withdraw_run (void *cls, } TALER_planchet_setup_random (&ws->ps); ws->is = is; - - dpk = TALER_TESTING_find_pk (TALER_EXCHANGE_get_keys (is->exchange), - &ws->amount); - if (NULL == dpk) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Failed to determine denomination key at %s\n", - (NULL != cmd) ? cmd->label : ""); - GNUNET_assert (0); - } - else + if (NULL == ws->pk) { + dpk = TALER_TESTING_find_pk (TALER_EXCHANGE_get_keys (is->exchange), + &ws->amount); + if (NULL == dpk) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to determine denomination key at %s\n", + (NULL != cmd) ? cmd->label : ""); + GNUNET_break (0); + TALER_TESTING_interpreter_fail (is); + return; + } /* We copy the denomination key, as re-querying /keys * would free the old one. */ ws->pk = TALER_EXCHANGE_copy_denomination_key (dpk); } - ws->wsh = TALER_EXCHANGE_reserve_withdraw (is->exchange, ws->pk, rp,