From 9d0e810049affc4077398d42c3c1bb7856a3b5bd Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Fri, 2 Apr 2021 14:12:47 +0200 Subject: fix misc memory leaks --- .../taler-merchant-httpd_post-orders-ID-claim.c | 1 + .../taler-merchant-httpd_post-tips-ID-pickup.c | 8 +++ ...merchant-httpd_private-patch-orders-ID-forget.c | 1 + .../taler-merchant-httpd_private-post-orders.c | 68 +++++++++++++++++----- .../taler-merchant-httpd_private-post-products.c | 2 + 5 files changed, 64 insertions(+), 16 deletions(-) (limited to 'src/backend') diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-claim.c b/src/backend/taler-merchant-httpd_post-orders-ID-claim.c index f82ed061..b764c7d7 100644 --- a/src/backend/taler-merchant-httpd_post-orders-ID-claim.c +++ b/src/backend/taler-merchant-httpd_post-orders-ID-claim.c @@ -238,6 +238,7 @@ TMH_post_orders_ID_claim (const struct TMH_RequestHandler *rh, &pdps.hash)) { GNUNET_break (0); + json_decref (contract_terms); return TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, TALER_EC_GENERIC_FAILED_COMPUTE_JSON_HASH, diff --git a/src/backend/taler-merchant-httpd_post-tips-ID-pickup.c b/src/backend/taler-merchant-httpd_post-tips-ID-pickup.c index c97c7587..5c695010 100644 --- a/src/backend/taler-merchant-httpd_post-tips-ID-pickup.c +++ b/src/backend/taler-merchant-httpd_post-tips-ID-pickup.c @@ -772,6 +772,7 @@ TMH_post_tips_ID_pickup (const struct TMH_RequestHandler *rh, GNUNET_NO, &compute_total_requested, pc); + GNUNET_free (exchange_url); return MHD_YES; } @@ -839,6 +840,7 @@ RETRY: &pc->planchets[i], i); } + GNUNET_free (exchange_url); if (rollback) return MHD_YES; /* we got _all_ signatures, can continue! */ @@ -915,6 +917,7 @@ RETRY: } if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) { + GNUNET_free (exchange_url); TMH_db->rollback (TMH_db->cls); return TALER_MHD_reply_with_error (connection, MHD_HTTP_GONE, @@ -926,6 +929,7 @@ RETRY: &total_authorized, &total_picked_up)) { + GNUNET_free (exchange_url); GNUNET_break_op (0); TMH_db->rollback (TMH_db->cls); return TALER_MHD_reply_with_error (connection, @@ -939,6 +943,7 @@ RETRY: &pc->total_requested)) { /* total_remaining < pc->total_requested */ + GNUNET_free (exchange_url); GNUNET_break_op (0); TMH_db->rollback (TMH_db->cls); return TALER_MHD_reply_with_error (connection, @@ -962,6 +967,7 @@ RETRY: TMH_db->rollback (TMH_db->cls); if (GNUNET_DB_STATUS_SOFT_ERROR == qs) goto RETRY; + GNUNET_free (exchange_url); return TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, TALER_EC_GENERIC_DB_STORE_FAILED, @@ -973,6 +979,7 @@ RETRY: TMH_db->rollback (TMH_db->cls); if (GNUNET_DB_STATUS_SOFT_ERROR == qs) goto RETRY; + GNUNET_free (exchange_url); return TALER_MHD_reply_with_error (connection, MHD_HTTP_INTERNAL_SERVER_ERROR, TALER_EC_GENERIC_DB_COMMIT_FAILED, @@ -989,5 +996,6 @@ RETRY: &pc->planchets[i], i); } + GNUNET_free (exchange_url); return MHD_YES; } diff --git a/src/backend/taler-merchant-httpd_private-patch-orders-ID-forget.c b/src/backend/taler-merchant-httpd_private-patch-orders-ID-forget.c index 494787ed..2ec8193a 100644 --- a/src/backend/taler-merchant-httpd_private-patch-orders-ID-forget.c +++ b/src/backend/taler-merchant-httpd_private-patch-orders-ID-forget.c @@ -46,6 +46,7 @@ forget (void *cls, json_t *parent) { int *res = cls; + if (GNUNET_OK != TALER_JSON_contract_part_forget (parent, object_id)) diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c index e2103ecc..fabbacf8 100644 --- a/src/backend/taler-merchant-httpd_private-post-orders.c +++ b/src/backend/taler-merchant-httpd_private-post-orders.c @@ -450,8 +450,9 @@ execute_order (struct MHD_Connection *connection, GNUNET_JSON_parse_free (spec); return qs; } - else if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) + if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs) { + json_decref (contract_terms); /* Comparing the contract terms is sufficient because all the other params get added to it at some point. */ if (0 == GNUNET_memcmp (&orig_post, @@ -537,27 +538,62 @@ execute_order (struct MHD_Connection *connection, { unsigned int i = -qs + PRODUCT_OOS_OFFSET; struct TALER_MERCHANTDB_ProductDetails pd; + MHD_RESULT ret; + memset (&pd, 0, sizeof (pd)); qs = TMH_db->lookup_product (TMH_db->cls, hc->instance->settings.id, inventory_products[i].product_id, &pd); GNUNET_JSON_parse_free (spec); - return TALER_MHD_reply_json_pack (connection, - MHD_HTTP_GONE, - "{s:s,s:I,s:I,s:o?}", - "product_id", - inventory_products[i].product_id, - "requested_quantity", - inventory_products[i].quantity, - "available_quantity", - pd.total_stock - pd.total_sold - - pd.total_lost, - "restock_expected", - (pd.next_restock.abs_value_us == 0) ? - NULL : - GNUNET_JSON_from_time_abs ( - pd.next_restock)); + switch (qs) + { + case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: + ret = TALER_MHD_reply_json_pack (connection, + MHD_HTTP_GONE, + "{s:s,s:I,s:I,s:o?}", + "product_id", + inventory_products[i].product_id, + "requested_quantity", + inventory_products[i].quantity, + "available_quantity", + pd.total_stock - pd.total_sold + - pd.total_lost, + "restock_expected", + (pd.next_restock.abs_value_us == 0) ? + NULL : + GNUNET_JSON_from_time_abs ( + pd.next_restock)); + TALER_MERCHANTDB_product_details_free (&pd); + break; + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: + ret = TALER_MHD_reply_json_pack (connection, + MHD_HTTP_GONE, + "{s:s,s:I,s:I}", + "product_id", + inventory_products[i].product_id, + "requested_quantity", + inventory_products[i].quantity, + "available_quantity", + (json_int_t) 0); + break; + case GNUNET_DB_STATUS_SOFT_ERROR: + GNUNET_break (0); + ret = TALER_MHD_reply_with_error ( + connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_SOFT_FAILURE, + NULL); + break; + case GNUNET_DB_STATUS_HARD_ERROR: + ret = TALER_MHD_reply_with_error ( + connection, + MHD_HTTP_INTERNAL_SERVER_ERROR, + TALER_EC_GENERIC_DB_FETCH_FAILED, + NULL); + break; + } + return ret; } /* Other hard transaction error (disk full, etc.) */ diff --git a/src/backend/taler-merchant-httpd_private-post-products.c b/src/backend/taler-merchant-httpd_private-post-products.c index 5b783519..c9ce24a6 100644 --- a/src/backend/taler-merchant-httpd_private-post-products.c +++ b/src/backend/taler-merchant-httpd_private-post-products.c @@ -159,6 +159,7 @@ TMH_private_post_products (const struct TMH_RequestHandler *rh, if (products_equal (&pd, &epd)) { + TALER_MERCHANTDB_product_details_free (&epd); TMH_db->rollback (TMH_db->cls); GNUNET_JSON_parse_free (spec); return TALER_MHD_reply_static (connection, @@ -169,6 +170,7 @@ TMH_private_post_products (const struct TMH_RequestHandler *rh, } else { + TALER_MERCHANTDB_product_details_free (&epd); TMH_db->rollback (TMH_db->cls); GNUNET_JSON_parse_free (spec); return TALER_MHD_reply_with_error (connection, -- cgit v1.2.3