leak fixes

This commit is contained in:
Christian Grothoff 2020-01-19 22:23:57 +01:00
parent 12468e1fd8
commit e46467510d
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
4 changed files with 70 additions and 32 deletions

View File

@ -175,6 +175,21 @@ static char *remote_host;
*/ */
static char *remote_dir; 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 * Don't kill exchange/fakebank/wirewatch until
* requested by the user explicitly. * requested by the user explicitly.
@ -182,8 +197,27 @@ static char *remote_dir;
static int linger; 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 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 return TALER_TESTING_cmd_admin_add_incoming_retry
(TALER_TESTING_cmd_admin_add_incoming (label, (TALER_TESTING_cmd_admin_add_incoming (label,
@ -283,9 +317,8 @@ run (void *cls,
j); j);
{ {
struct TALER_TESTING_Command make_reserve[] = { struct TALER_TESTING_Command make_reserve[] = {
CMD_TRANSFER_TO_EXCHANGE (create_reserve_label, cmd_transfer_to_exchange (add_label (create_reserve_label),
TALER_amount_to_string TALER_amount2s (&total_reserve_amount)),
(&total_reserve_amount)),
TALER_TESTING_cmd_end () TALER_TESTING_cmd_end ()
}; };
char *batch_label; char *batch_label;
@ -294,7 +327,7 @@ run (void *cls,
"batch-start-%u", "batch-start-%u",
j); j);
all_commands[j * (howmany_coins + 1)] all_commands[j * (howmany_coins + 1)]
= TALER_TESTING_cmd_batch (batch_label, = TALER_TESTING_cmd_batch (add_label (batch_label),
make_reserve); make_reserve);
} }
for (unsigned int i = 0; i < howmany_coins; i++) for (unsigned int i = 0; i < howmany_coins; i++)
@ -313,17 +346,17 @@ run (void *cls,
i + (howmany_coins * j)); i + (howmany_coins * j));
unit[0] = unit[0] =
TALER_TESTING_cmd_withdraw_with_retry 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, create_reserve_label,
amount_5, amount_5,
MHD_HTTP_OK)); MHD_HTTP_OK));
unit[1] = unit[1] =
TALER_TESTING_cmd_deposit_with_retry TALER_TESTING_cmd_deposit_with_retry
(TALER_TESTING_cmd_deposit ("deposit", (TALER_TESTING_cmd_deposit ("deposit",
withdraw_label, add_label (withdraw_label),
0, /* Index of the one withdrawn coin in the traits. */ 0, /* Index of the one withdrawn coin in the traits. */
user_payto_uri, user_payto_uri,
order_enc, add_label (order_enc),
GNUNET_TIME_UNIT_ZERO, GNUNET_TIME_UNIT_ZERO,
amount_1, amount_1,
MHD_HTTP_OK)); MHD_HTTP_OK));
@ -341,16 +374,16 @@ run (void *cls,
i, i,
j); j);
unit[2] = unit[2] =
TALER_TESTING_cmd_refresh_melt_with_retry ( TALER_TESTING_cmd_refresh_melt_with_retry
TALER_TESTING_cmd_refresh_melt (TALER_TESTING_cmd_refresh_melt
(melt_label, (add_label (melt_label),
withdraw_label, withdraw_label,
MHD_HTTP_OK, MHD_HTTP_OK,
NULL)); NULL));
unit[3] = unit[3] =
TALER_TESTING_cmd_refresh_reveal_with_retry TALER_TESTING_cmd_refresh_reveal_with_retry
(TALER_TESTING_cmd_refresh_reveal (TALER_TESTING_cmd_refresh_reveal
(reveal_label, (add_label (reveal_label),
melt_label, melt_label,
MHD_HTTP_OK)); MHD_HTTP_OK));
unit[4] = unit[4] =
@ -369,7 +402,7 @@ run (void *cls,
i, i,
j); j);
all_commands[j * (howmany_coins + 1) + (1 + i)] all_commands[j * (howmany_coins + 1) + (1 + i)]
= TALER_TESTING_cmd_batch (unit_label, = TALER_TESTING_cmd_batch (add_label (unit_label),
unit); unit);
} }
} }
@ -962,5 +995,10 @@ main (int argc,
(unsigned long long) (usage.ru_utime.tv_sec * 1000 * 1000 (unsigned long long) (usage.ru_utime.tv_sec * 1000 * 1000
+ usage.ru_utime.tv_usec)); + usage.ru_utime.tv_usec));
} }
for (unsigned int i = 0; i<label_off; i++)
GNUNET_free (labels[i]);
GNUNET_array_grow (labels,
label_len,
0);
return (GNUNET_OK == result) ? 0 : result; return (GNUNET_OK == result) ? 0 : result;
} }

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# #
# This file is part of TALER # This file is part of TALER
# Copyright (C) 2015 GNUnet e.V. # Copyright (C) 2015, 2020 Taler Systems SA
# #
# TALER is free software; you can redistribute it and/or modify it under the # TALER is free software; you can redistribute it and/or modify it under the
# terms of the GNU Affero General Public License as published by the Free Software # terms of the GNU Affero General Public License as published by the Free Software
@ -21,21 +21,22 @@
# #
# We read the JSON snippets from afl-tests/ # We read the JSON snippets from afl-tests/
# #
set -eu
PREFIX= PREFIX=
# Uncomment this line to run with valgrind... # Uncomment this line to run with valgrind...
PREFIX="valgrind --leak-check=yes --log-file=valgrind.%p" # PREFIX="valgrind --leak-check=yes --log-file=valgrind.%p"
# Setup keys. # Setup keys.
taler-exchange-keyup -d test-exchange-home -m test-exchange-home/master.priv taler-exchange-keyup -c test_taler_exchange_httpd.conf
# Setup database (just to be sure) # Setup database (just to be sure)
taler-exchange-dbinit -d test-exchange-home &> /dev/null || true taler-exchange-dbinit -c test_taler_exchange_httpd.conf &> /dev/null
# Only log hard errors, we expect lots of warnings... # Only log hard errors, we expect lots of warnings...
export GNUNET_FORCE_LOG="taler-exchange-httpd;;;;ERROR/libmicrohttpd;;;;ERROR/util;;;;ERROR/" export GNUNET_FORCE_LOG="taler-exchange-httpd;;;;ERROR/libmicrohttpd;;;;ERROR/util;;;;ERROR/"
# Run test... # Run test...
for n in afl-tests/* for n in afl-tests/*
do do
echo -n "Test $n " 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 -c test_taler_exchange_httpd.conf -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; }
echo "OK" echo "OK"
done done
exit 0 exit 0

View File

@ -2156,7 +2156,6 @@ TALER_EXCHANGE_destroy_denomination_key (struct
TALER_EXCHANGE_DenomPublicKey *key) TALER_EXCHANGE_DenomPublicKey *key)
{ {
GNUNET_CRYPTO_rsa_public_key_free (key->key.rsa_public_key);; GNUNET_CRYPTO_rsa_public_key_free (key->key.rsa_public_key);;
key->key.rsa_public_key = NULL;
GNUNET_free (key); GNUNET_free (key);
} }

View File

@ -263,23 +263,23 @@ withdraw_run (void *cls,
} }
TALER_planchet_setup_random (&ws->ps); TALER_planchet_setup_random (&ws->ps);
ws->is = is; ws->is = is;
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 : "<retried command>");
GNUNET_assert (0);
}
else
{ {
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 : "<retried command>");
GNUNET_break (0);
TALER_TESTING_interpreter_fail (is);
return;
}
/* We copy the denomination key, as re-querying /keys /* We copy the denomination key, as re-querying /keys
* would free the old one. */ * would free the old one. */
ws->pk = TALER_EXCHANGE_copy_denomination_key (dpk); ws->pk = TALER_EXCHANGE_copy_denomination_key (dpk);
} }
ws->wsh = TALER_EXCHANGE_reserve_withdraw (is->exchange, ws->wsh = TALER_EXCHANGE_reserve_withdraw (is->exchange,
ws->pk, ws->pk,
rp, rp,