adding checks to avoid re-initializing memory and removing [0]-type hack, however, this now causes a segv (NPE)

This commit is contained in:
Christian Grothoff 2015-08-06 18:19:59 +02:00
parent 94ffa282b7
commit f655ce9ad1
3 changed files with 69 additions and 54 deletions

View File

@ -127,7 +127,7 @@ PERF_TALER_MINTDB_denomination_copy (const struct TALER_MINTDB_DenominationKeyIs
int int
PERF_TALER_MINTDB_denomination_free (struct TALER_MINTDB_DenominationKeyIssueInformation *dki) PERF_TALER_MINTDB_denomination_free (struct TALER_MINTDB_DenominationKeyIssueInformation *dki)
{ {
if (NULL ==dki) if (NULL == dki)
return GNUNET_OK; return GNUNET_OK;
GNUNET_CRYPTO_rsa_private_key_free (dki->denom_priv.rsa_private_key); GNUNET_CRYPTO_rsa_private_key_free (dki->denom_priv.rsa_private_key);
GNUNET_CRYPTO_rsa_public_key_free (dki->denom_pub.rsa_public_key); GNUNET_CRYPTO_rsa_public_key_free (dki->denom_pub.rsa_public_key);

View File

@ -61,42 +61,43 @@ data_free (struct PERF_TALER_MINTDB_Data *data)
{ {
case PERF_TALER_MINTDB_TIME: case PERF_TALER_MINTDB_TIME:
if (NULL == data->data.time) if (NULL == data->data.time)
return; break;
GNUNET_free (data->data.time); GNUNET_free (data->data.time);
data->data.time = NULL; data->data.time = NULL;
return; break;
case PERF_TALER_MINTDB_DEPOSIT: case PERF_TALER_MINTDB_DEPOSIT:
if (NULL == data->data.deposit) if (NULL == data->data.deposit)
return; break;
PERF_TALER_MINTDB_deposit_free (data->data.deposit); PERF_TALER_MINTDB_deposit_free (data->data.deposit);
data->data.deposit = NULL; data->data.deposit = NULL;
return; break;
case PERF_TALER_MINTDB_COIN: case PERF_TALER_MINTDB_COIN:
if (NULL == data->data.coin) if (NULL == data->data.coin)
return; break;
PERF_TALER_MINTDB_coin_free (data->data.coin); PERF_TALER_MINTDB_coin_free (data->data.coin);
data->data.coin = NULL; data->data.coin = NULL;
return; break;
case PERF_TALER_MINTDB_RESERVE: case PERF_TALER_MINTDB_RESERVE:
if (NULL == data->data.reserve) if (NULL == data->data.reserve)
return; break;
PERF_TALER_MINTDB_reserve_free (data->data.reserve); PERF_TALER_MINTDB_reserve_free (data->data.reserve);
data->data.reserve = NULL; data->data.reserve = NULL;
return; break;
case PERF_TALER_MINTDB_DENOMINATION_INFO: case PERF_TALER_MINTDB_DENOMINATION_INFO:
if (NULL == data->data.dki) if (NULL == data->data.dki)
return; break;
PERF_TALER_MINTDB_denomination_free (data->data.dki); PERF_TALER_MINTDB_denomination_free (data->data.dki);
data->data.dki = NULL; data->data.dki = NULL;
return; break;
default: default:
return; break;
} }
data->type = PERF_TALER_MINTDB_NONE;
} }
@ -107,8 +108,10 @@ data_free (struct PERF_TALER_MINTDB_Data *data)
* @param[out] copy the copy made * @param[out] copy the copy made
*/ */
static void static void
data_copy (const struct PERF_TALER_MINTDB_Data *data, struct PERF_TALER_MINTDB_Data *copy) data_copy (const struct PERF_TALER_MINTDB_Data *data,
struct PERF_TALER_MINTDB_Data *copy)
{ {
GNUNET_assert (PERF_TALER_MINTDB_NONE == copy->type);
copy->type = data->type; copy->type = data->type;
switch (data->type) switch (data->type)
{ {
@ -150,7 +153,8 @@ data_copy (const struct PERF_TALER_MINTDB_Data *data, struct PERF_TALER_MINTDB_D
* #GNUNET_SYSERR if none found * #GNUNET_SYSERR if none found
*/ */
static int static int
cmd_find (const struct PERF_TALER_MINTDB_Cmd *cmd, const char *search) cmd_find (const struct PERF_TALER_MINTDB_Cmd *cmd,
const char *search)
{ {
unsigned int i; unsigned int i;
@ -252,7 +256,7 @@ cmd_init (struct PERF_TALER_MINTDB_Cmd cmd[])
cmd[i].details.save_array.data_saved = cmd[i].details.save_array.data_saved =
GNUNET_new_array (cmd[i].details.save_array.nb_saved, GNUNET_new_array (cmd[i].details.save_array.nb_saved,
struct PERF_TALER_MINTDB_Data); struct PERF_TALER_MINTDB_Data);
cmd[i].details.save_array.data_saved[0].type = cmd[i].details.save_array.type_saved =
cmd[cmd[i].details.save_array.index_save].exposed.type; cmd[cmd[i].details.save_array.index_save].exposed.type;
} }
break; break;
@ -307,7 +311,7 @@ cmd_init (struct PERF_TALER_MINTDB_Cmd cmd[])
cmd[cmd[i].details.load_array.index_save].details.save_array.nb_saved); cmd[cmd[i].details.load_array.index_save].details.save_array.nb_saved);
GNUNET_assert (NULL != cmd[i].details.load_array.permutation); GNUNET_assert (NULL != cmd[i].details.load_array.permutation);
cmd[i].exposed.type = cmd[cmd[i].details.load_array.index_save].details.save_array.data_saved->type; cmd[i].exposed.type = cmd[cmd[i].details.load_array.index_save].details.save_array.type_saved;
} }
break; break;
@ -760,8 +764,10 @@ interpret_load_array (struct PERF_TALER_MINTDB_interpreter_state *state)
/* Extracting the data from the loop_indexth indice in save_index /* Extracting the data from the loop_indexth indice in save_index
* array. * array.
*/ */
data_free (&cmd->exposed);
loaded_data = &state->cmd[save_index].details.save_array.data_saved[loop_iter]; loaded_data = &state->cmd[save_index].details.save_array.data_saved[loop_iter];
data_copy (loaded_data, &cmd->exposed); data_copy (loaded_data,
&cmd->exposed);
} }
@ -777,6 +783,7 @@ interprete_load_random (struct PERF_TALER_MINTDB_interpreter_state *state)
unsigned int index; unsigned int index;
int save_index; int save_index;
data_free (&cmd->exposed);
save_index = cmd->details.load_random.index_save; save_index = cmd->details.load_random.index_save;
index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
state->cmd[save_index].details.save_array.nb_saved); state->cmd[save_index].details.save_array.nb_saved);
@ -784,6 +791,7 @@ interprete_load_random (struct PERF_TALER_MINTDB_interpreter_state *state)
&cmd->exposed); &cmd->exposed);
} }
/** /**
* Iterate over the commands, acting accordingly at each step * Iterate over the commands, acting accordingly at each step
* *

View File

@ -18,12 +18,12 @@
* @brief Library for performance analysis of the Taler database * @brief Library for performance analysis of the Taler database
* @author Nicolas Fournier * @author Nicolas Fournier
* *
* This library contains functions and macro alowing Taler performance analysis * This library contains functions and macro alowing Taler performance analysis
* to be written with ease. * to be written with ease.
* To do so, create a #PERF_TALER_MINTDB_Cmd array and fill it with the commands * To do so, create a #PERF_TALER_MINTDB_Cmd array and fill it with the commands
* to execute in chronological order. Some command have an exposed variable wich * to execute in chronological order. Some command have an exposed variable wich
* can be reused in other commands. * can be reused in other commands.
* Macros are available to make the use much easier so feel free to use them * Macros are available to make the use much easier so feel free to use them
* to initialize your own command array. * to initialize your own command array.
*/ */
@ -62,7 +62,7 @@
/** /**
* Prints @ _label to stdout * Prints @ _label to stdout
* *
* @param _label The label of the command, * @param _label The label of the command,
* will be logged each time the command runs * will be logged each time the command runs
*/ */
@ -75,7 +75,7 @@
/** /**
* The begining of a loop * The begining of a loop
* *
* @param _label the label of the loop * @param _label the label of the loop
* @param _iter the number of iterations of the loop * @param _iter the number of iterations of the loop
*/ */
@ -91,9 +91,9 @@
/** /**
* Marks the end of the loop @_label_loop * Marks the end of the loop @_label_loop
* *
* @param _label the label of the command * @param _label the label of the command
* @param _label_loop the label of the loop closed by this command * @param _label_loop the label of the loop closed by this command
*/ */
#define PERF_TALER_MINTDB_INIT_CMD_END_LOOP(_label, _label_loop) \ #define PERF_TALER_MINTDB_INIT_CMD_END_LOOP(_label, _label_loop) \
{\ {\
@ -124,7 +124,7 @@
* @param _label_stop label of the end of the measurment * @param _label_stop label of the end of the measurment
* @param _description description of the measure displayed in Gauger * @param _description description of the measure displayed in Gauger
* @param _unit the unit of the data measured, typicly something/sec * @param _unit the unit of the data measured, typicly something/sec
* @param _divide number of measurments in the interval * @param _divide number of measurments in the interval
*/ */
#define PERF_TALER_MINTDB_INIT_CMD_GAUGER(_label, _label_start, _label_stop, _category, _description, _unit, _divide) \ #define PERF_TALER_MINTDB_INIT_CMD_GAUGER(_label, _label_start, _label_stop, _category, _description, _unit, _divide) \
{ \ { \
@ -143,7 +143,7 @@
/** /**
* Initiate a database transaction * Initiate a database transaction
* *
* @param _label the label of the command * @param _label the label of the command
*/ */
#define PERF_TALER_MINTDB_INIT_CMD_START_TRANSACTION(_label) \ #define PERF_TALER_MINTDB_INIT_CMD_START_TRANSACTION(_label) \
@ -155,7 +155,7 @@
/** /**
* Commits a database transaction * Commits a database transaction
* *
* @param _label the label of the command * @param _label the label of the command
*/ */
#define PERF_TALER_MINTDB_INIT_CMD_COMMIT_TRANSACTION(_label) \ #define PERF_TALER_MINTDB_INIT_CMD_COMMIT_TRANSACTION(_label) \
@ -176,9 +176,9 @@
.label = _label, .label = _label,
/** /**
* Saves randomly selected items from @a _label_save * Saves randomly selected items from @a _label_save
* Saved items can latter be access using #PERF_TALER_MINTDB_CMD_LOAD_ARRAY * Saved items can latter be access using #PERF_TALER_MINTDB_CMD_LOAD_ARRAY
* *
* @param _label the label of the command, used by other commands to reference it * @param _label the label of the command, used by other commands to reference it
* @param _label_loop the label of the loop the array iterates over * @param _label_loop the label of the loop the array iterates over
* @param _label_save the label of the command which outout is saved by this command * @param _label_save the label of the command which outout is saved by this command
@ -199,7 +199,7 @@
/** /**
* Loads data from a #PERF_TALER_MINTDB_CMD_SAVE_ARRAY to allow other * Loads data from a #PERF_TALER_MINTDB_CMD_SAVE_ARRAY to allow other
* commands to access it * commands to access it
* *
* @param _label the label of this command, referenced by commands to access it's outpout * @param _label the label of this command, referenced by commands to access it's outpout
* @param _label_loop the label of the loop to iterate over * @param _label_loop the label of the loop to iterate over
* @param _label_save the label of the #PERF_TALER_MINTDB_CMD_SAVE_ARRAY providing data * @param _label_save the label of the #PERF_TALER_MINTDB_CMD_SAVE_ARRAY providing data
@ -219,7 +219,7 @@
* Inserts informations about a denomination key in the database * Inserts informations about a denomination key in the database
* Exposes a #PERF_TALER_MINTDB_DENOMINATION_INFO to be used by other commands * Exposes a #PERF_TALER_MINTDB_DENOMINATION_INFO to be used by other commands
* @exposed #PERF_TALER_MINTDB_DENOMINATION_INFO * @exposed #PERF_TALER_MINTDB_DENOMINATION_INFO
* *
* @param _label the label of this command * @param _label the label of this command
*/ */
#define PERF_TALER_MINTDB_INIT_CMD_INSERT_DENOMINATION(_label) \ #define PERF_TALER_MINTDB_INIT_CMD_INSERT_DENOMINATION(_label) \
@ -231,7 +231,7 @@
/** /**
* Polls the database about informations regarding a specific denomination key * Polls the database about informations regarding a specific denomination key
* *
* @param _label the label of this command * @param _label the label of this command
* @param _label_denom the label of the command providing information about the denomination key * @param _label_denom the label of the command providing information about the denomination key
*/ */
@ -244,11 +244,11 @@
} }
/** /**
* Creates a new reserve in the database containing 1000 Euros * Creates a new reserve in the database containing 1000 Euros
* Exposes a #PERF_TALER_MINTDB_RESERVE * Exposes a #PERF_TALER_MINTDB_RESERVE
* *
* @exposed #PERF_TALER_MINTDB_RESERVE * @exposed #PERF_TALER_MINTDB_RESERVE
* *
* @param _label the name of this command * @param _label the name of this command
*/ */
#define PERF_TALER_MINTDB_INIT_CMD_INSERT_RESERVE(_label) \ #define PERF_TALER_MINTDB_INIT_CMD_INSERT_RESERVE(_label) \
@ -261,7 +261,7 @@
/** /**
* Polls the database for a secific reserve's details * Polls the database for a secific reserve's details
* *
* @param _label the label of this command * @param _label the label of this command
* @param _label_reserve the reserve to poll * @param _label_reserve the reserve to poll
*/ */
@ -341,12 +341,12 @@
*/ */
#define PERF_TALER_MONTDB_INIT_CMD_DEPOSIT(_label, _label_coin)\ #define PERF_TALER_MONTDB_INIT_CMD_DEPOSIT(_label, _label_coin)\
PERF_TALER_MINTDB_INIT_CMD_INSERT_DEPOSIT (_label ":insert deposit", _label_coin), \ PERF_TALER_MINTDB_INIT_CMD_INSERT_DEPOSIT (_label ":insert deposit", _label_coin), \
PERF_TALER_MINTDB_INIT_CMD_GET_DEPOSIT (_label ":get deposit", _label ":insert deposit") PERF_TALER_MINTDB_INIT_CMD_GET_DEPOSIT (_label ":get deposit", _label ":insert deposit")
/** /**
* Inserts informations about a withdrawal in the database * Inserts informations about a withdrawal in the database
* *
* @exposes #PERF_TALER_MINTDB_COIN * @exposes #PERF_TALER_MINTDB_COIN
* *
* @param _label the label of this command * @param _label the label of this command
@ -367,7 +367,7 @@
/** /**
* Polls the database about informations regarding a specific withdrawal * Polls the database about informations regarding a specific withdrawal
* *
* @param _label the label of this command * @param _label the label of this command
* @param _label_coin the coin to check * @param _label_coin the coin to check
*/ */
@ -382,7 +382,7 @@
/** /**
* The /withdraw/sign api call * The /withdraw/sign api call
* *
* Exposes #PERF_TALER_MINTDB_COIN * Exposes #PERF_TALER_MINTDB_COIN
* *
* @param _label the label of this command * @param _label the label of this command
@ -395,11 +395,11 @@
PERF_TALER_MINTDB_INIT_CMD_INSERT_WITHDRAW(_label "insert withdraw", \ PERF_TALER_MINTDB_INIT_CMD_INSERT_WITHDRAW(_label "insert withdraw", \
_label_dki, \ _label_dki, \
_label_reserve) _label_reserve)
/** /**
* The /deposit api call * The /deposit api call
* *
* @param _label the label of the command * @param _label the label of the command
* @param _label_coin the coin used for the deposit * @param _label_coin the coin used for the deposit
*/ */
@ -442,7 +442,7 @@ struct PERF_TALER_MINTDB_Data
struct GNUNET_TIME_Absolute *time; struct GNUNET_TIME_Absolute *time;
/** #PERF_TALER_MINTDB_DEPOSIT */ /** #PERF_TALER_MINTDB_DEPOSIT */
struct TALER_MINTDB_Deposit *deposit; struct TALER_MINTDB_Deposit *deposit;
/** #PERF_TALER_MINTDB_COIN */ /** #PERF_TALER_MINTDB_COIN */
struct PERF_TALER_MINTDB_Coin *coin; struct PERF_TALER_MINTDB_Coin *coin;
/** #PERF_TALER_MINTDB_RESERVE */ /** #PERF_TALER_MINTDB_RESERVE */
struct PERF_TALER_MINTDB_Reserve *reserve; struct PERF_TALER_MINTDB_Reserve *reserve;
@ -469,9 +469,9 @@ enum PERF_TALER_MINTDB_CMD_Name
*/ */
PERF_TALER_MINTDB_CMD_DEBUG, PERF_TALER_MINTDB_CMD_DEBUG,
/** /**
* Define the start of al command chain loop * Define the start of al command chain loop
*/ */
PERF_TALER_MINTDB_CMD_LOOP, PERF_TALER_MINTDB_CMD_LOOP,
/** /**
@ -662,7 +662,7 @@ union PERF_TALER_MINTDB_CMD_Details
struct PERF_TALER_MINTDB_CMD_loopDetails struct PERF_TALER_MINTDB_CMD_loopDetails
{ {
/** /**
* Maximum number of iteration in the loop * Maximum number of iteration in the loop
*/ */
const unsigned int max_iterations; const unsigned int max_iterations;
@ -740,23 +740,30 @@ union PERF_TALER_MINTDB_CMD_Details
* Number of items already saved * Number of items already saved
*/ */
unsigned int index; unsigned int index;
/** /**
* Label of the loop it is attached to * Label of the loop it is attached to
*/ */
const char *label_loop; const char *label_loop;
unsigned int index_loop; unsigned int index_loop;
/** /**
* Label of the command exposing the item * Label of the command exposing the item
*/ */
const char *label_save; const char *label_save;
unsigned int index_save; unsigned int index_save;
/** /**
* Array of data saved * Array of data saved
*/ */
struct PERF_TALER_MINTDB_Data *data_saved; struct PERF_TALER_MINTDB_Data *data_saved;
/**
* Type of the data that will be stored in @a data_saved, for
* 'static' type checking.
*/
enum PERF_TALER_MINTDB_Type type_saved;
} save_array; } save_array;
@ -797,7 +804,7 @@ union PERF_TALER_MINTDB_CMD_Details
} load_random; } load_random;
/** /**
* Data used by the #PERF_TALER_MINTDB_CMD_INSERT_DEPOSIT command * Data used by the #PERF_TALER_MINTDB_CMD_INSERT_DEPOSIT command
*/ */
struct PERF_TALER_MINTDB_CMD_insertDepositDetails struct PERF_TALER_MINTDB_CMD_insertDepositDetails
{ {
@ -893,7 +900,7 @@ union PERF_TALER_MINTDB_CMD_Details
/** /**
* Data requiered for the #PERF_TALER_MINTDB_CMD_GET_COIN_TRANSACTION command * Data requiered for the #PERF_TALER_MINTDB_CMD_GET_COIN_TRANSACTION command
*/ */
struct PERF_TALER_MINTDB_CMD_getCoinTransactionDetails struct PERF_TALER_MINTDB_CMD_getCoinTransactionDetails
{ {
/** /**
@ -953,7 +960,7 @@ union PERF_TALER_MINTDB_CMD_Details
/** /**
* The refresh session hash * The refresh session hash
*/ */
const char *label_hash; const char *label_hash;
unsigned int index_hash; unsigned int index_hash;
/** /**
@ -1097,7 +1104,7 @@ struct PERF_TALER_MINTDB_Cmd
* *
* @param benchmark_name the name of the benchmark, displayed in the logs * @param benchmark_name the name of the benchmark, displayed in the logs
* @param configuration_file path to the taler configuration file to use * @param configuration_file path to the taler configuration file to use
* @param init the commands to use for the database initialisation, * @param init the commands to use for the database initialisation,
* if #NULL the standard initialization is used * if #NULL the standard initialization is used
* @param benchmark the commands for the benchmark * @param benchmark the commands for the benchmark
* @return GNUNET_OK upon success; GNUNET_SYSERR upon failure * @return GNUNET_OK upon success; GNUNET_SYSERR upon failure
@ -1112,7 +1119,7 @@ PERF_TALER_MINTDB_run_benchmark (const char *benchmark_name,
/** /**
* Runs the command array @a cmd * Runs the command array @a cmd
* using @a db_plugin to connect to the database * using @a db_plugin to connect to the database
* *
* @param db_plugin the connection to the database * @param db_plugin the connection to the database
* @param cmd the commands to run * @param cmd the commands to run
*/ */