diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-04-02 14:12:47 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-04-02 14:12:47 +0200 |
commit | 9d0e810049affc4077398d42c3c1bb7856a3b5bd (patch) | |
tree | d958804a0a4f32f1bced5539976cc116c88036e7 | |
parent | 6ae58fdc8e11cefdbee3419d52151e43f8a09590 (diff) |
fix misc memory leaks
-rw-r--r-- | src/backend/taler-merchant-httpd_post-orders-ID-claim.c | 1 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_post-tips-ID-pickup.c | 8 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_private-patch-orders-ID-forget.c | 1 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-orders.c | 68 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-products.c | 2 | ||||
-rw-r--r-- | src/backenddb/Makefile.am | 3 | ||||
-rw-r--r-- | src/backenddb/merchantdb_helper.c | 38 | ||||
-rw-r--r-- | src/include/taler_merchantdb_lib.h | 10 | ||||
-rw-r--r-- | src/lib/merchant_api_tip_pickup.c | 2 | ||||
-rw-r--r-- | src/testing/test_merchant_api.c | 2 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_get_orders.c | 3 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_get_tips.c | 3 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_merchant_get_order.c | 7 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_tip_authorize.c | 3 |
14 files changed, 131 insertions, 20 deletions
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, diff --git a/src/backenddb/Makefile.am b/src/backenddb/Makefile.am index 6c428fdc..edcb62ee 100644 --- a/src/backenddb/Makefile.am +++ b/src/backenddb/Makefile.am @@ -33,7 +33,8 @@ lib_LTLIBRARIES = \ libtalermerchantdb.la libtalermerchantdb_la_SOURCES = \ - merchantdb_plugin.c + merchantdb_plugin.c \ + merchantdb_helper.c libtalermerchantdb_la_LIBADD = \ $(LIBGCRYPT_LIBS) \ diff --git a/src/backenddb/merchantdb_helper.c b/src/backenddb/merchantdb_helper.c new file mode 100644 index 00000000..516a5788 --- /dev/null +++ b/src/backenddb/merchantdb_helper.c @@ -0,0 +1,38 @@ +/* + This file is part of TALER + Copyright (C) 2021 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU Lesser General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> +*/ +/** + * @file merchantdb_helper.c + * @brief Helper functions for the merchant database logic + * @author Christian Grothoff + */ +#include "platform.h" +#include <taler/taler_util.h> +#include "taler_merchantdb_lib.h" + + +void +TALER_MERCHANTDB_product_details_free (struct TALER_MERCHANTDB_ProductDetails *pd) +{ + GNUNET_free (pd->description); + json_decref (pd->description_i18n); + GNUNET_free (pd->unit); + json_decref (pd->taxes); + json_decref (pd->image); + json_decref (pd->address); +} + + +/* end of merchantdb_helper.c */ diff --git a/src/include/taler_merchantdb_lib.h b/src/include/taler_merchantdb_lib.h index e24198ef..35fb5c12 100644 --- a/src/include/taler_merchantdb_lib.h +++ b/src/include/taler_merchantdb_lib.h @@ -49,6 +49,16 @@ void TALER_MERCHANTDB_plugin_unload (struct TALER_MERCHANTDB_Plugin *dbh); +/** + * Free members of @a pd, but not @a pd itself. + * + * @param[in] pd product details to clean up + */ +void +TALER_MERCHANTDB_product_details_free (struct + TALER_MERCHANTDB_ProductDetails *pd); + + #endif /* MERCHANT_DB_H */ /* end of taler_merchantdb_lib.h */ diff --git a/src/lib/merchant_api_tip_pickup.c b/src/lib/merchant_api_tip_pickup.c index 5f27b93b..2045cf0a 100644 --- a/src/lib/merchant_api_tip_pickup.c +++ b/src/lib/merchant_api_tip_pickup.c @@ -234,7 +234,7 @@ void TALER_MERCHANT_tip_pickup_cancel (struct TALER_MERCHANT_TipPickupHandle *tp) { for (unsigned int i = 0; i<tp->num_planchets; i++) - GNUNET_CRYPTO_rsa_public_key_dup (tp->planchets[i].pk.key.rsa_public_key); + GNUNET_CRYPTO_rsa_public_key_free (tp->planchets[i].pk.key.rsa_public_key); GNUNET_array_grow (tp->planchets, tp->num_planchets, 0); diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c index 93b6194f..8b5c46bc 100644 --- a/src/testing/test_merchant_api.c +++ b/src/testing/test_merchant_api.c @@ -1264,7 +1264,7 @@ run (void *cls, GNUNET_TIME_UNIT_MINUTES, // FIXME: change this back once // we have a update auth test CMD - //RFC_8959_PREFIX "EXAMPLE", + // RFC_8959_PREFIX "EXAMPLE", NULL, MHD_HTTP_NO_CONTENT), TALER_TESTING_cmd_merchant_patch_instance ("instance-patch-ACL", diff --git a/src/testing/testing_api_cmd_get_orders.c b/src/testing/testing_api_cmd_get_orders.c index 0a3b39a3..51292c3c 100644 --- a/src/testing/testing_api_cmd_get_orders.c +++ b/src/testing/testing_api_cmd_get_orders.c @@ -231,6 +231,9 @@ get_orders_cleanup (void *cls, "GET /orders operation did not complete\n"); TALER_MERCHANT_orders_get_cancel (gos->ogh); } + GNUNET_array_grow (gos->orders, + gos->orders_length, + 0); GNUNET_free (gos); } diff --git a/src/testing/testing_api_cmd_get_tips.c b/src/testing/testing_api_cmd_get_tips.c index 7b481d04..12b0f56c 100644 --- a/src/testing/testing_api_cmd_get_tips.c +++ b/src/testing/testing_api_cmd_get_tips.c @@ -222,6 +222,9 @@ get_tips_cleanup (void *cls, "GET /private/tips operation did not complete\n"); TALER_MERCHANT_tips_get_cancel (gts->tgh); } + GNUNET_array_grow (gts->tips, + gts->tips_length, + 0); GNUNET_free (gts); } diff --git a/src/testing/testing_api_cmd_merchant_get_order.c b/src/testing/testing_api_cmd_merchant_get_order.c index 6e408d89..c08dd56e 100644 --- a/src/testing/testing_api_cmd_merchant_get_order.c +++ b/src/testing/testing_api_cmd_merchant_get_order.c @@ -478,13 +478,19 @@ merchant_get_order_cb ( TALER_TESTING_get_trait_order_id (order_cmd, 0, &order_id)) + { + TALER_MERCHANT_parse_pay_uri_free (&pud); TALER_TESTING_FAIL (gos->is); + } if (GNUNET_OK != TALER_TESTING_get_trait_claim_token (order_cmd, 0, &claim_token)) + { + TALER_MERCHANT_parse_pay_uri_free (&pud); TALER_TESTING_FAIL (gos->is); + } { char *port; char *host; @@ -536,6 +542,7 @@ merchant_get_order_cb ( TALER_MERCHANT_parse_pay_uri_free (&pud); return; } + TALER_MERCHANT_parse_pay_uri_free (&pud); } break; } diff --git a/src/testing/testing_api_cmd_tip_authorize.c b/src/testing/testing_api_cmd_tip_authorize.c index 62868ecd..3fb4c1bc 100644 --- a/src/testing/testing_api_cmd_tip_authorize.c +++ b/src/testing/testing_api_cmd_tip_authorize.c @@ -71,7 +71,7 @@ struct TipAuthorizeState /** * Tip taler:// URI. */ - const char *tip_uri; + char *tip_uri; /** * The tip id; set when the CMD succeeds. @@ -332,6 +332,7 @@ tip_authorize_cleanup (void *cls, GNUNET_SCHEDULER_cancel (tas->retry_task); tas->retry_task = NULL; } + GNUNET_free (tas->tip_uri); GNUNET_free (tas); } |