simplify logic, fix leak
This commit is contained in:
parent
12deb6c267
commit
246f3a7f94
@ -174,12 +174,6 @@ struct HelperState
|
|||||||
*/
|
*/
|
||||||
struct GNUNET_CONTAINER_MultiPeerMap *esign_keys;
|
struct GNUNET_CONTAINER_MultiPeerMap *esign_keys;
|
||||||
|
|
||||||
/**
|
|
||||||
* Cached reply for a GET /management/keys request. Used so we do not
|
|
||||||
* re-create the reply every time.
|
|
||||||
*/
|
|
||||||
json_t *management_keys_reply;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -277,6 +271,12 @@ struct TEH_KeyStateHandle
|
|||||||
*/
|
*/
|
||||||
struct HelperState *helpers;
|
struct HelperState *helpers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cached reply for a GET /management/keys request. Used so we do not
|
||||||
|
* re-create the reply every time.
|
||||||
|
*/
|
||||||
|
json_t *management_keys_reply;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For which (global) key_generation was this data structure created?
|
* For which (global) key_generation was this data structure created?
|
||||||
* Used to check when we are outdated and need to be re-generated.
|
* Used to check when we are outdated and need to be re-generated.
|
||||||
@ -592,11 +592,6 @@ destroy_key_helpers (struct HelperState *hs)
|
|||||||
TALER_CRYPTO_helper_esign_disconnect (hs->esh);
|
TALER_CRYPTO_helper_esign_disconnect (hs->esh);
|
||||||
hs->esh = NULL;
|
hs->esh = NULL;
|
||||||
}
|
}
|
||||||
if (NULL != hs->management_keys_reply)
|
|
||||||
{
|
|
||||||
json_decref (hs->management_keys_reply);
|
|
||||||
hs->management_keys_reply = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -663,11 +658,6 @@ helper_denom_cb (
|
|||||||
&hd->h_denom_pub,
|
&hd->h_denom_pub,
|
||||||
hd,
|
hd,
|
||||||
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
|
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
|
||||||
if (NULL != hs->management_keys_reply)
|
|
||||||
{
|
|
||||||
json_decref (hs->management_keys_reply);
|
|
||||||
hs->management_keys_reply = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -729,11 +719,6 @@ helper_esign_cb (
|
|||||||
&pid,
|
&pid,
|
||||||
hsk,
|
hsk,
|
||||||
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
|
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
|
||||||
if (NULL != hs->management_keys_reply)
|
|
||||||
{
|
|
||||||
json_decref (hs->management_keys_reply);
|
|
||||||
hs->management_keys_reply = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -865,6 +850,11 @@ destroy_key_state (struct TEH_KeyStateHandle *ksh,
|
|||||||
destroy_key_helpers (ksh->helpers);
|
destroy_key_helpers (ksh->helpers);
|
||||||
GNUNET_free (ksh->helpers);
|
GNUNET_free (ksh->helpers);
|
||||||
}
|
}
|
||||||
|
if (NULL != ksh->management_keys_reply)
|
||||||
|
{
|
||||||
|
json_decref (ksh->management_keys_reply);
|
||||||
|
ksh->management_keys_reply = NULL;
|
||||||
|
}
|
||||||
GNUNET_free (ksh);
|
GNUNET_free (ksh);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1649,6 +1639,7 @@ build_key_state (struct HelperState *hs,
|
|||||||
if (GNUNET_OK !=
|
if (GNUNET_OK !=
|
||||||
setup_key_helpers (ksh->helpers))
|
setup_key_helpers (ksh->helpers))
|
||||||
{
|
{
|
||||||
|
GNUNET_free (ksh->helpers);
|
||||||
GNUNET_free (ksh);
|
GNUNET_free (ksh);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -1781,8 +1772,11 @@ get_key_state (bool management_only)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (NULL != old_ksh)
|
if (NULL != old_ksh)
|
||||||
|
{
|
||||||
|
old_ksh->helpers = NULL;
|
||||||
destroy_key_state (old_ksh,
|
destroy_key_state (old_ksh,
|
||||||
false);
|
false);
|
||||||
|
}
|
||||||
return ksh;
|
return ksh;
|
||||||
}
|
}
|
||||||
sync_key_helpers (old_ksh->helpers);
|
sync_key_helpers (old_ksh->helpers);
|
||||||
@ -2433,7 +2427,7 @@ TEH_keys_management_get_handler (const struct TEH_RequestHandler *rh,
|
|||||||
"no key state");
|
"no key state");
|
||||||
}
|
}
|
||||||
sync_key_helpers (ksh->helpers);
|
sync_key_helpers (ksh->helpers);
|
||||||
if (NULL == ksh->helpers->management_keys_reply)
|
if (NULL == ksh->management_keys_reply)
|
||||||
{
|
{
|
||||||
struct FutureBuilderContext fbc = {
|
struct FutureBuilderContext fbc = {
|
||||||
.ksh = ksh,
|
.ksh = ksh,
|
||||||
@ -2468,11 +2462,12 @@ TEH_keys_management_get_handler (const struct TEH_RequestHandler *rh,
|
|||||||
MHD_HTTP_INTERNAL_SERVER_ERROR,
|
MHD_HTTP_INTERNAL_SERVER_ERROR,
|
||||||
TALER_EC_GENERIC_JSON_ALLOCATION_FAILURE,
|
TALER_EC_GENERIC_JSON_ALLOCATION_FAILURE,
|
||||||
NULL);
|
NULL);
|
||||||
ksh->helpers->management_keys_reply = json_incref (reply);
|
GNUNET_assert (NULL == ksh->management_keys_reply);
|
||||||
|
ksh->management_keys_reply = json_incref (reply);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
reply = json_incref (ksh->helpers->management_keys_reply);
|
reply = json_incref (ksh->management_keys_reply);
|
||||||
}
|
}
|
||||||
return TALER_MHD_reply_json (connection,
|
return TALER_MHD_reply_json (connection,
|
||||||
reply,
|
reply,
|
||||||
|
@ -198,7 +198,6 @@ build_wire_state (void)
|
|||||||
{
|
{
|
||||||
json_t *wire_accounts_array;
|
json_t *wire_accounts_array;
|
||||||
json_t *wire_fee_object;
|
json_t *wire_fee_object;
|
||||||
json_t *wire_reply;
|
|
||||||
uint64_t wg = wire_generation; /* must be obtained FIRST */
|
uint64_t wg = wire_generation; /* must be obtained FIRST */
|
||||||
enum GNUNET_DB_QueryStatus qs;
|
enum GNUNET_DB_QueryStatus qs;
|
||||||
|
|
||||||
@ -230,6 +229,7 @@ build_wire_state (void)
|
|||||||
char *wire_method;
|
char *wire_method;
|
||||||
const char *payto_uri = json_string_value (json_object_get (account,
|
const char *payto_uri = json_string_value (json_object_get (account,
|
||||||
"payto_uri"));
|
"payto_uri"));
|
||||||
|
|
||||||
GNUNET_assert (NULL != payto_uri);
|
GNUNET_assert (NULL != payto_uri);
|
||||||
wire_method = TALER_payto_get_method (payto_uri);
|
wire_method = TALER_payto_get_method (payto_uri);
|
||||||
if (NULL == wire_method)
|
if (NULL == wire_method)
|
||||||
@ -265,6 +265,7 @@ build_wire_state (void)
|
|||||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||||
"No wire fees for `%s' configured. Administrator must set `wire-fee` with taler-exchange-offline!\n",
|
"No wire fees for `%s' configured. Administrator must set `wire-fee` with taler-exchange-offline!\n",
|
||||||
wire_method);
|
wire_method);
|
||||||
|
json_decref (a);
|
||||||
json_decref (wire_accounts_array);
|
json_decref (wire_accounts_array);
|
||||||
json_decref (wire_fee_object);
|
json_decref (wire_fee_object);
|
||||||
GNUNET_free (wire_method);
|
GNUNET_free (wire_method);
|
||||||
@ -276,25 +277,25 @@ build_wire_state (void)
|
|||||||
a));
|
a));
|
||||||
}
|
}
|
||||||
GNUNET_free (wire_method);
|
GNUNET_free (wire_method);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wire_reply = json_pack (
|
|
||||||
"{s:o, s:o, s:o}",
|
|
||||||
"accounts",
|
|
||||||
wire_accounts_array,
|
|
||||||
"fees",
|
|
||||||
wire_fee_object,
|
|
||||||
"master_public_key",
|
|
||||||
GNUNET_JSON_from_data_auto (&TEH_master_public_key));
|
|
||||||
if (NULL == wire_reply)
|
|
||||||
{
|
|
||||||
GNUNET_break (0);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
{
|
{
|
||||||
|
json_t *wire_reply;
|
||||||
struct WireStateHandle *wsh;
|
struct WireStateHandle *wsh;
|
||||||
|
|
||||||
|
wire_reply = json_pack (
|
||||||
|
"{s:o, s:o, s:o}",
|
||||||
|
"accounts",
|
||||||
|
wire_accounts_array,
|
||||||
|
"fees",
|
||||||
|
wire_fee_object,
|
||||||
|
"master_public_key",
|
||||||
|
GNUNET_JSON_from_data_auto (&TEH_master_public_key));
|
||||||
|
if (NULL == wire_reply)
|
||||||
|
{
|
||||||
|
GNUNET_break (0);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
wsh = GNUNET_new (struct WireStateHandle);
|
wsh = GNUNET_new (struct WireStateHandle);
|
||||||
wsh->wire_reply = wire_reply;
|
wsh->wire_reply = wire_reply;
|
||||||
wsh->wire_generation = wg;
|
wsh->wire_generation = wg;
|
||||||
@ -322,12 +323,13 @@ struct WireStateHandle *
|
|||||||
get_wire_state (void)
|
get_wire_state (void)
|
||||||
{
|
{
|
||||||
struct WireStateHandle *old_wsh;
|
struct WireStateHandle *old_wsh;
|
||||||
struct WireStateHandle *wsh;
|
|
||||||
|
|
||||||
old_wsh = pthread_getspecific (wire_state);
|
old_wsh = pthread_getspecific (wire_state);
|
||||||
if ( (NULL == old_wsh) ||
|
if ( (NULL == old_wsh) ||
|
||||||
(old_wsh->wire_generation < wire_generation) )
|
(old_wsh->wire_generation < wire_generation) )
|
||||||
{
|
{
|
||||||
|
struct WireStateHandle *wsh;
|
||||||
|
|
||||||
wsh = build_wire_state ();
|
wsh = build_wire_state ();
|
||||||
if (NULL == wsh)
|
if (NULL == wsh)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user