aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-02-13 18:22:07 +0100
committerChristian Grothoff <christian@grothoff.org>2021-02-13 18:22:07 +0100
commit246f3a7f948b5e50109e7adfaf4170fb3e096409 (patch)
treee9295d59caedc73cd093fd10c46785133e519f98
parent12deb6c2670f663a3c0734e28673f508fffa3210 (diff)
simplify logic, fix leak
-rw-r--r--src/exchange/taler-exchange-httpd_keys.c43
-rw-r--r--src/exchange/taler-exchange-httpd_wire.c34
2 files changed, 37 insertions, 40 deletions
diff --git a/src/exchange/taler-exchange-httpd_keys.c b/src/exchange/taler-exchange-httpd_keys.c
index df49b93f9..6515bc3d8 100644
--- a/src/exchange/taler-exchange-httpd_keys.c
+++ b/src/exchange/taler-exchange-httpd_keys.c
@@ -174,12 +174,6 @@ struct HelperState
*/
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;
-
};
@@ -278,6 +272,12 @@ struct TEH_KeyStateHandle
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?
* 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);
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,
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,
hsk,
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);
GNUNET_free (ksh->helpers);
}
+ if (NULL != ksh->management_keys_reply)
+ {
+ json_decref (ksh->management_keys_reply);
+ ksh->management_keys_reply = NULL;
+ }
GNUNET_free (ksh);
}
@@ -1649,6 +1639,7 @@ build_key_state (struct HelperState *hs,
if (GNUNET_OK !=
setup_key_helpers (ksh->helpers))
{
+ GNUNET_free (ksh->helpers);
GNUNET_free (ksh);
return NULL;
}
@@ -1781,8 +1772,11 @@ get_key_state (bool management_only)
return NULL;
}
if (NULL != old_ksh)
+ {
+ old_ksh->helpers = NULL;
destroy_key_state (old_ksh,
false);
+ }
return ksh;
}
sync_key_helpers (old_ksh->helpers);
@@ -2433,7 +2427,7 @@ TEH_keys_management_get_handler (const struct TEH_RequestHandler *rh,
"no key state");
}
sync_key_helpers (ksh->helpers);
- if (NULL == ksh->helpers->management_keys_reply)
+ if (NULL == ksh->management_keys_reply)
{
struct FutureBuilderContext fbc = {
.ksh = ksh,
@@ -2468,11 +2462,12 @@ TEH_keys_management_get_handler (const struct TEH_RequestHandler *rh,
MHD_HTTP_INTERNAL_SERVER_ERROR,
TALER_EC_GENERIC_JSON_ALLOCATION_FAILURE,
NULL);
- ksh->helpers->management_keys_reply = json_incref (reply);
+ GNUNET_assert (NULL == ksh->management_keys_reply);
+ ksh->management_keys_reply = json_incref (reply);
}
else
{
- reply = json_incref (ksh->helpers->management_keys_reply);
+ reply = json_incref (ksh->management_keys_reply);
}
return TALER_MHD_reply_json (connection,
reply,
diff --git a/src/exchange/taler-exchange-httpd_wire.c b/src/exchange/taler-exchange-httpd_wire.c
index e01355c60..8f78f3b60 100644
--- a/src/exchange/taler-exchange-httpd_wire.c
+++ b/src/exchange/taler-exchange-httpd_wire.c
@@ -198,7 +198,6 @@ build_wire_state (void)
{
json_t *wire_accounts_array;
json_t *wire_fee_object;
- json_t *wire_reply;
uint64_t wg = wire_generation; /* must be obtained FIRST */
enum GNUNET_DB_QueryStatus qs;
@@ -230,6 +229,7 @@ build_wire_state (void)
char *wire_method;
const char *payto_uri = json_string_value (json_object_get (account,
"payto_uri"));
+
GNUNET_assert (NULL != payto_uri);
wire_method = TALER_payto_get_method (payto_uri);
if (NULL == wire_method)
@@ -265,6 +265,7 @@ build_wire_state (void)
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"No wire fees for `%s' configured. Administrator must set `wire-fee` with taler-exchange-offline!\n",
wire_method);
+ json_decref (a);
json_decref (wire_accounts_array);
json_decref (wire_fee_object);
GNUNET_free (wire_method);
@@ -276,25 +277,25 @@ build_wire_state (void)
a));
}
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;
+ 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->wire_reply = wire_reply;
wsh->wire_generation = wg;
@@ -322,12 +323,13 @@ struct WireStateHandle *
get_wire_state (void)
{
struct WireStateHandle *old_wsh;
- struct WireStateHandle *wsh;
old_wsh = pthread_getspecific (wire_state);
if ( (NULL == old_wsh) ||
(old_wsh->wire_generation < wire_generation) )
{
+ struct WireStateHandle *wsh;
+
wsh = build_wire_state ();
if (NULL == wsh)
return NULL;