export function to free commit coin data

This commit is contained in:
Christian Grothoff 2016-05-19 18:37:31 +02:00
parent 7d8a74adf1
commit 9391ed529c
3 changed files with 33 additions and 36 deletions

View File

@ -3107,12 +3107,14 @@ postgres_insert_refresh_commit_coins (void *cls,
* We allocated some @a commit_coin information, but now need
* to abort. Free allocated memory.
*
* @param commit_coins data to free (but not the array itself)
* @param cls unused
* @param commit_coins_len length of @a commit_coins array
* @param commit_coins data to free (but not the array itself)
*/
static void
free_cc_result (struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coins,
unsigned int commit_coins_len)
postgres_free_refresh_commit_coins (void *cls,
unsigned int commit_coins_len,
struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coins)
{
unsigned int i;
@ -3174,13 +3176,13 @@ postgres_get_refresh_commit_coins (void *cls,
{
BREAK_DB_ERR (result);
PQclear (result);
free_cc_result (commit_coins, i);
postgres_free_refresh_commit_coins (cls, i, commit_coins);
return GNUNET_SYSERR;
}
if (0 == PQntuples (result))
{
PQclear (result);
free_cc_result (commit_coins, i);
postgres_free_refresh_commit_coins (cls, i, commit_coins);
return GNUNET_NO;
}
{
@ -3198,7 +3200,7 @@ postgres_get_refresh_commit_coins (void *cls,
GNUNET_PQ_extract_result (result, rs, 0))
{
PQclear (result);
free_cc_result (commit_coins, i);
postgres_free_refresh_commit_coins (cls, i, commit_coins);
return GNUNET_SYSERR;
}
}
@ -3207,7 +3209,7 @@ postgres_get_refresh_commit_coins (void *cls,
{
GNUNET_free (c_buf);
GNUNET_free (rl_buf);
free_cc_result (commit_coins, i);
postgres_free_refresh_commit_coins (cls, i, commit_coins);
return GNUNET_SYSERR;
}
rl = TALER_refresh_link_encrypted_decode (rl_buf,
@ -4315,7 +4317,7 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
}
else
{
if (GNUNET_OK ==
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
"exchangedb-postgres",
"db_conn_str",
@ -4358,6 +4360,7 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
plugin->get_refresh_order = &postgres_get_refresh_order;
plugin->insert_refresh_commit_coins = &postgres_insert_refresh_commit_coins;
plugin->get_refresh_commit_coins = &postgres_get_refresh_commit_coins;
plugin->free_refresh_commit_coins = &postgres_free_refresh_commit_coins;
plugin->insert_refresh_commit_link = &postgres_insert_refresh_commit_link;
plugin->get_refresh_commit_link = &postgres_get_refresh_commit_link;
plugin->get_melt_commitment = &postgres_get_melt_commitment;

View File

@ -293,31 +293,6 @@ static struct TALER_Amount fee_refund;
static struct TALER_Amount amount_with_fee;
/**
* Free memory associated with @a commit_coins.
*
* @param commit_coins memory to release
* @param size size of the @a commit_coins array
*/
static void
free_refresh_commit_coins_array (struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coins,
unsigned int size)
{
unsigned int cnt;
struct TALER_EXCHANGEDB_RefreshCommitCoin *ccoin;
struct TALER_RefreshLinkEncrypted *rlink;
for (cnt = 0; cnt < size; cnt++)
{
ccoin = &commit_coins[cnt];
GNUNET_free_non_null (ccoin->coin_ev);
rlink = (struct TALER_RefreshLinkEncrypted *) ccoin->refresh_link;
GNUNET_free_non_null (rlink);
}
GNUNET_free (commit_coins);
}
/**
* Compare two coin encrypted refresh links.
*
@ -474,7 +449,12 @@ test_refresh_commit_coins (struct TALER_EXCHANGEDB_Session *session,
drop:
if (NULL != ret_commit_coins)
free_refresh_commit_coins_array (ret_commit_coins, MELT_NEW_COINS);
{
plugin->free_refresh_commit_coins (plugin->cls,
MELT_NEW_COINS,
ret_commit_coins);
GNUNET_free (ret_commit_coins);
}
return ret;
}
@ -811,8 +791,10 @@ test_melting (struct TALER_EXCHANGEDB_Session *session)
for (cnt=0;cnt<TALER_CNC_KAPPA;cnt++)
if (NULL != commit_coins[cnt])
{
free_refresh_commit_coins_array (commit_coins[cnt],
MELT_NEW_COINS);
plugin->free_refresh_commit_coins (plugin->cls,
MELT_NEW_COINS,
commit_coins[cnt]);
GNUNET_free (commit_coins[cnt]);
commit_coins[cnt] = NULL;
}
if (NULL != dkp)

View File

@ -1189,6 +1189,18 @@ struct TALER_EXCHANGEDB_Plugin
uint16_t num_coins,
struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coins);
/**
* Free refresh @a commit_coins data obtained via @e get_refresh_commit_coins.
*
* @param cls the @e cls of this struct with the plugin-specific state
* @param num_coins size of the @a commit_coins array
* @param commit_coins array of coin commitments to free
*/
void
(*free_refresh_commit_coins) (void *cls,
unsigned int num_coins,
struct TALER_EXCHANGEDB_RefreshCommitCoin *commit_coins);
/**
* Store the commitment to the given (encrypted) refresh link data