mintdb get_known_coin(): Do not allocate memory for return paramter.
Instead populate the fields of the placeholder return variable.
This commit is contained in:
parent
02c237d269
commit
1d551bf36b
@ -332,7 +332,7 @@ struct TALER_MINTDB_RefreshMelt
|
|||||||
*/
|
*/
|
||||||
struct TALER_Amount amount_with_fee;
|
struct TALER_Amount amount_with_fee;
|
||||||
|
|
||||||
/**
|
/** FIXME: This can be retrieved from the Denomination? Do we need this?
|
||||||
* Melting fee charged by the mint. This must match the Mint's
|
* Melting fee charged by the mint. This must match the Mint's
|
||||||
* denomination key's melting fee. If the client puts in an invalid
|
* denomination key's melting fee. If the client puts in an invalid
|
||||||
* melting fee (too high or too low) that does not match the Mint's
|
* melting fee (too high or too low) that does not match the Mint's
|
||||||
@ -848,7 +848,7 @@ struct TALER_MINTDB_Plugin
|
|||||||
* @param cls the plugin closure
|
* @param cls the plugin closure
|
||||||
* @param session the database session handle
|
* @param session the database session handle
|
||||||
* @param coin_pub the public key of the coin to search for
|
* @param coin_pub the public key of the coin to search for
|
||||||
* @param ret_coin_info place holder for the returned coin information object
|
* @param coin_info place holder for the returned coin information object
|
||||||
* @return #GNUNET_SYSERR upon error; #GNUNET_NO if no coin is found; #GNUNET_OK
|
* @return #GNUNET_SYSERR upon error; #GNUNET_NO if no coin is found; #GNUNET_OK
|
||||||
* if upon succesfullying retrieving the record data info @a
|
* if upon succesfullying retrieving the record data info @a
|
||||||
* ret_coin_info
|
* ret_coin_info
|
||||||
@ -857,7 +857,7 @@ struct TALER_MINTDB_Plugin
|
|||||||
(*get_known_coin) (void *cls,
|
(*get_known_coin) (void *cls,
|
||||||
struct TALER_MINTDB_Session *session,
|
struct TALER_MINTDB_Session *session,
|
||||||
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
||||||
struct TALER_CoinPublicInfo **ret_coin_info);
|
struct TALER_CoinPublicInfo *coin_info);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1641,23 +1641,24 @@ postgres_insert_known_coin (void *cls,
|
|||||||
* @param cls the plugin closure
|
* @param cls the plugin closure
|
||||||
* @param session the database session handle
|
* @param session the database session handle
|
||||||
* @param coin_pub the public key of the coin to search for
|
* @param coin_pub the public key of the coin to search for
|
||||||
* @param ret_coin_info place holder for the returned coin information object
|
* @param coin_info place holder for the returned coin information object
|
||||||
* @return #GNUNET_SYSERR upon error; #GNUNET_NO if no coin is found; #GNUNET_OK
|
* @return #GNUNET_SYSERR upon error; #GNUNET_NO if no coin is found; #GNUNET_OK
|
||||||
* if upon succesfullying retrieving the record data info @a
|
* if upon succesfullying retrieving the record data info @a
|
||||||
* ret_coin_info
|
* coin_info
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
postgres_get_known_coin (void *cls,
|
postgres_get_known_coin (void *cls,
|
||||||
struct TALER_MINTDB_Session *session,
|
struct TALER_MINTDB_Session *session,
|
||||||
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
const struct TALER_CoinSpendPublicKeyP *coin_pub,
|
||||||
struct TALER_CoinPublicInfo **ret_coin_info)
|
struct TALER_CoinPublicInfo *coin_info)
|
||||||
{
|
{
|
||||||
PGresult *result;
|
PGresult *result;
|
||||||
struct TALER_PQ_QueryParam params[] = {
|
struct TALER_PQ_QueryParam params[] = {
|
||||||
TALER_PQ_query_param_auto_from_type (coin_pub),
|
TALER_PQ_query_param_auto_from_type (coin_pub),
|
||||||
TALER_PQ_query_param_end
|
TALER_PQ_query_param_end
|
||||||
};
|
};
|
||||||
struct TALER_CoinPublicInfo *coin_info;
|
int nrows;
|
||||||
|
|
||||||
result = TALER_PQ_exec_prepared (session->conn,
|
result = TALER_PQ_exec_prepared (session->conn,
|
||||||
"get_known_coin",
|
"get_known_coin",
|
||||||
params);
|
params);
|
||||||
@ -1667,17 +1668,13 @@ postgres_get_known_coin (void *cls,
|
|||||||
PQclear (result);
|
PQclear (result);
|
||||||
return GNUNET_SYSERR;
|
return GNUNET_SYSERR;
|
||||||
}
|
}
|
||||||
if (0 == PQntuples (result))
|
nrows = PQntuples (result);
|
||||||
|
if (0 == nrows)
|
||||||
{
|
{
|
||||||
PQclear (result);
|
PQclear (result);
|
||||||
return GNUNET_NO;
|
return GNUNET_NO;
|
||||||
}
|
}
|
||||||
if ((NULL == ret_coin_info) && (1 == PQntuples (result)))
|
GNUNET_assert (1 == nrows); /* due to primary key */
|
||||||
{
|
|
||||||
PQclear (result);
|
|
||||||
return GNUNET_OK;
|
|
||||||
}
|
|
||||||
coin_info = GNUNET_new (struct TALER_CoinPublicInfo);
|
|
||||||
struct TALER_PQ_ResultSpec rs[] = {
|
struct TALER_PQ_ResultSpec rs[] = {
|
||||||
TALER_PQ_result_spec_rsa_public_key ("denom_pub", &coin_info->denom_pub.rsa_public_key),
|
TALER_PQ_result_spec_rsa_public_key ("denom_pub", &coin_info->denom_pub.rsa_public_key),
|
||||||
TALER_PQ_result_spec_rsa_signature ("denom_sig", &coin_info->denom_sig.rsa_signature),
|
TALER_PQ_result_spec_rsa_signature ("denom_sig", &coin_info->denom_sig.rsa_signature),
|
||||||
@ -1691,10 +1688,11 @@ postgres_get_known_coin (void *cls,
|
|||||||
return GNUNET_SYSERR;
|
return GNUNET_SYSERR;
|
||||||
}
|
}
|
||||||
PQclear (result);
|
PQclear (result);
|
||||||
|
/* no need to copy if the src and dest are same */
|
||||||
|
if (coin_pub != &coin_info->coin_pub)
|
||||||
(void) memcpy (&coin_info->coin_pub,
|
(void) memcpy (&coin_info->coin_pub,
|
||||||
coin_pub,
|
coin_pub,
|
||||||
sizeof (struct TALER_CoinSpendPublicKeyP));
|
sizeof (struct TALER_CoinSpendPublicKeyP));
|
||||||
*ret_coin_info = coin_info;
|
|
||||||
return GNUNET_OK;
|
return GNUNET_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ static int
|
|||||||
test_known_coins (struct TALER_MINTDB_Session *session)
|
test_known_coins (struct TALER_MINTDB_Session *session)
|
||||||
{
|
{
|
||||||
struct TALER_CoinPublicInfo coin_info;
|
struct TALER_CoinPublicInfo coin_info;
|
||||||
struct TALER_CoinPublicInfo *ret_coin_info;
|
struct TALER_CoinPublicInfo ret_coin_info;
|
||||||
struct DenomKeyPair *dkp;
|
struct DenomKeyPair *dkp;
|
||||||
int ret = GNUNET_SYSERR;
|
int ret = GNUNET_SYSERR;
|
||||||
|
|
||||||
@ -190,13 +190,11 @@ test_known_coins (struct TALER_MINTDB_Session *session)
|
|||||||
coin_info.denom_sig.rsa_signature =
|
coin_info.denom_sig.rsa_signature =
|
||||||
GNUNET_CRYPTO_rsa_sign (dkp->priv.rsa_private_key,
|
GNUNET_CRYPTO_rsa_sign (dkp->priv.rsa_private_key,
|
||||||
"foobar", 6);
|
"foobar", 6);
|
||||||
ret_coin_info = NULL;
|
|
||||||
FAILIF (GNUNET_NO !=
|
FAILIF (GNUNET_NO !=
|
||||||
plugin->get_known_coin (plugin->cls,
|
plugin->get_known_coin (plugin->cls,
|
||||||
session,
|
session,
|
||||||
&coin_info.coin_pub,
|
&coin_info.coin_pub,
|
||||||
&ret_coin_info));
|
&ret_coin_info));
|
||||||
FAILIF (NULL != ret_coin_info);
|
|
||||||
FAILIF (GNUNET_OK !=
|
FAILIF (GNUNET_OK !=
|
||||||
plugin->insert_known_coin (plugin->cls,
|
plugin->insert_known_coin (plugin->cls,
|
||||||
session,
|
session,
|
||||||
@ -206,23 +204,18 @@ test_known_coins (struct TALER_MINTDB_Session *session)
|
|||||||
session,
|
session,
|
||||||
&coin_info.coin_pub,
|
&coin_info.coin_pub,
|
||||||
&ret_coin_info));
|
&ret_coin_info));
|
||||||
FAILIF (NULL == ret_coin_info);
|
|
||||||
FAILIF (0 != GNUNET_CRYPTO_rsa_public_key_cmp
|
FAILIF (0 != GNUNET_CRYPTO_rsa_public_key_cmp
|
||||||
(ret_coin_info->denom_pub.rsa_public_key,
|
(ret_coin_info.denom_pub.rsa_public_key,
|
||||||
coin_info.denom_pub.rsa_public_key));
|
coin_info.denom_pub.rsa_public_key));
|
||||||
FAILIF (0 != GNUNET_CRYPTO_rsa_signature_cmp
|
FAILIF (0 != GNUNET_CRYPTO_rsa_signature_cmp
|
||||||
(ret_coin_info->denom_sig.rsa_signature,
|
(ret_coin_info.denom_sig.rsa_signature,
|
||||||
coin_info.denom_sig.rsa_signature));
|
coin_info.denom_sig.rsa_signature));
|
||||||
|
GNUNET_CRYPTO_rsa_public_key_free (ret_coin_info.denom_pub.rsa_public_key);
|
||||||
|
GNUNET_CRYPTO_rsa_signature_free (ret_coin_info.denom_sig.rsa_signature);
|
||||||
ret = GNUNET_OK;
|
ret = GNUNET_OK;
|
||||||
drop:
|
drop:
|
||||||
destroy_denom_key_pair (dkp);
|
destroy_denom_key_pair (dkp);
|
||||||
GNUNET_CRYPTO_rsa_signature_free (coin_info.denom_sig.rsa_signature);
|
GNUNET_CRYPTO_rsa_signature_free (coin_info.denom_sig.rsa_signature);
|
||||||
if (NULL != ret_coin_info)
|
|
||||||
{
|
|
||||||
GNUNET_CRYPTO_rsa_public_key_free (ret_coin_info->denom_pub.rsa_public_key);
|
|
||||||
GNUNET_CRYPTO_rsa_signature_free (ret_coin_info->denom_sig.rsa_signature);
|
|
||||||
GNUNET_free (ret_coin_info);
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user