diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-05-19 18:37:31 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-05-19 18:37:31 +0200 |
commit | 9391ed529c5b20dd8ad1114e28ca1e6dcb1de190 (patch) | |
tree | d0034b6e4f91ce420429ac4cf1bc121088e4abec /src | |
parent | 7d8a74adf1a0b2451140aa07c183b12d16ae6a38 (diff) |
export function to free commit coin data
Diffstat (limited to 'src')
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 19 | ||||
-rw-r--r-- | src/exchangedb/test_exchangedb.c | 38 | ||||
-rw-r--r-- | src/include/taler_exchangedb_plugin.h | 12 |
3 files changed, 33 insertions, 36 deletions
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index c5965ae1f..eee31bdc0 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -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; diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c index e15d657e5..a5530e3cc 100644 --- a/src/exchangedb/test_exchangedb.c +++ b/src/exchangedb/test_exchangedb.c @@ -294,31 +294,6 @@ 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. * * @param rc1 first commitment @@ -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) diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h index 4c6f546f9..56e226071 100644 --- a/src/include/taler_exchangedb_plugin.h +++ b/src/include/taler_exchangedb_plugin.h @@ -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 |