diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-06-11 19:38:12 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-06-11 19:38:12 +0200 |
commit | c70b560da01eae609664433590123ecd64d68396 (patch) | |
tree | 06986bb6bbd732070e6fdd7f65e99e6057773fc3 | |
parent | 489eaecb1d8669a6827c94b2d1e9ac84bbeab2ad (diff) | |
download | merchant-c70b560da01eae609664433590123ecd64d68396.tar.gz merchant-c70b560da01eae609664433590123ecd64d68396.tar.bz2 merchant-c70b560da01eae609664433590123ecd64d68396.zip |
fix more memory leaks
-rw-r--r-- | src/backend/taler-merchant-httpd.c | 14 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd.h | 29 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_contract.c | 39 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_exchanges.c | 7 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_pay.c | 38 | ||||
-rw-r--r-- | src/backenddb/plugin_merchantdb_postgres.c | 1 | ||||
-rw-r--r-- | src/backenddb/test_merchantdb.c | 12 |
7 files changed, 79 insertions, 61 deletions
diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c index b4bb64cb..f7bbe539 100644 --- a/src/backend/taler-merchant-httpd.c +++ b/src/backend/taler-merchant-httpd.c @@ -402,20 +402,6 @@ validate_and_hash_wireformat (const struct GNUNET_CONFIGURATION_Handle *cfg, /** - * Custom cleanup routine for a `struct PayContext`. - * - * @param hc the `struct PayContext` to clean up. - */ -void -TMH_json_parse_cleanup (struct TM_HandlerContext *hc) -{ - struct TMH_JsonParseContext *jpc = (struct TMH_JsonParseContext *) hc; - - TMH_PARSE_post_cleanup_callback (jpc->json_parse_context); -} - - -/** * Function that queries MHD's select sets and * starts the task waiting for them. * diff --git a/src/backend/taler-merchant-httpd.h b/src/backend/taler-merchant-httpd.h index 7fcfba02..4f368815 100644 --- a/src/backend/taler-merchant-httpd.h +++ b/src/backend/taler-merchant-httpd.h @@ -132,26 +132,6 @@ struct TM_HandlerContext /** - * Information we keep for an individual calls - * to requests that parse JSON, but keep no other state. - */ -struct TMH_JsonParseContext -{ - - /** - * This field MUST be first. - * FIXME: Explain why! - */ - struct TM_HandlerContext hc; - - /** - * Placeholder for #TMH_PARSE_post_json() to keep its internal state. - */ - void *json_parse_context; -}; - - -/** * Our wire format details in JSON format (with salt). */ extern json_t *j_wire; @@ -198,13 +178,4 @@ extern struct GNUNET_TIME_Relative wire_transfer_delay; void TMH_trigger_daemon (void); -/** - * Custom cleanup routine for a `struct PayContext`. - * - * @param hc the `struct PayContext` to clean up. - */ -void -TMH_json_parse_cleanup (struct TM_HandlerContext *hc); - - #endif diff --git a/src/backend/taler-merchant-httpd_contract.c b/src/backend/taler-merchant-httpd_contract.c index 072f8bad..722146b5 100644 --- a/src/backend/taler-merchant-httpd_contract.c +++ b/src/backend/taler-merchant-httpd_contract.c @@ -81,6 +81,41 @@ check_products (json_t *products) /** + * Information we keep for an individual calls + * to requests that parse JSON, but keep no other state. + */ +struct TMH_JsonParseContext +{ + + /** + * This field MUST be first. + * FIXME: Explain why! + */ + struct TM_HandlerContext hc; + + /** + * Placeholder for #TMH_PARSE_post_json() to keep its internal state. + */ + void *json_parse_context; +}; + + +/** + * Custom cleanup routine for a `struct TMH_JsonParseContext`. + * + * @param hc the `struct TMH_JsonParseContext` to clean up. + */ +static void +json_parse_cleanup (struct TM_HandlerContext *hc) +{ + struct TMH_JsonParseContext *jpc = (struct TMH_JsonParseContext *) hc; + + TMH_PARSE_post_cleanup_callback (jpc->json_parse_context); + GNUNET_free (jpc); +} + + +/** * Manage a contract request. In practical terms, it adds the fields * 'exchanges', 'merchant_pub', and 'H_wire' to the contract 'proposition' * gotten from the frontend. Finally, it adds (outside of the @@ -133,7 +168,7 @@ MH_handler_contract (struct TMH_RequestHandler *rh, if (NULL == *connection_cls) { ctx = GNUNET_new (struct TMH_JsonParseContext); - ctx->hc.cc = &TMH_json_parse_cleanup; + ctx->hc.cc = &json_parse_cleanup; *connection_cls = ctx; } else @@ -217,7 +252,7 @@ MH_handler_contract (struct TMH_RequestHandler *rh, /* return final response */ res = TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_OK, - "{s:O, s:O, s:O}", + "{s:O, s:o s:o}", "contract", jcontract, "merchant_sig", GNUNET_JSON_from_data_auto (&contract_sig), "H_contract", GNUNET_JSON_from_data_auto (&contract.h_contract)); diff --git a/src/backend/taler-merchant-httpd_exchanges.c b/src/backend/taler-merchant-httpd_exchanges.c index d54ce4b3..b928f485 100644 --- a/src/backend/taler-merchant-httpd_exchanges.c +++ b/src/backend/taler-merchant-httpd_exchanges.c @@ -518,8 +518,9 @@ TMH_EXCHANGES_init (const struct GNUNET_CONFIGURATION_Handle *cfg) struct Exchange *exchange; json_t *j_exchange; - merchant_curl_ctx = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule, - &merchant_curl_rc); + merchant_curl_ctx + = GNUNET_CURL_init (&GNUNET_CURL_gnunet_scheduler_reschedule, + &merchant_curl_rc); if (NULL == merchant_curl_ctx) { GNUNET_break (0); @@ -571,6 +572,8 @@ TMH_EXCHANGES_done () merchant_curl_ctx = NULL; GNUNET_CURL_gnunet_rc_destroy (merchant_curl_rc); merchant_curl_rc = NULL; + json_decref (trusted_exchanges); + trusted_exchanges = NULL; } /* end of taler-merchant-httpd_exchanges.c */ diff --git a/src/backend/taler-merchant-httpd_pay.c b/src/backend/taler-merchant-httpd_pay.c index a46f3223..a1320fa1 100644 --- a/src/backend/taler-merchant-httpd_pay.c +++ b/src/backend/taler-merchant-httpd_pay.c @@ -364,9 +364,9 @@ deposit_cb (void *cls, json_t *eproof; eproof = json_copy ((json_t *) proof); - json_object_set (eproof, - "coin_pub", - GNUNET_JSON_from_data_auto (&dc->coin_pub)); + json_object_set_new (eproof, + "coin_pub", + GNUNET_JSON_from_data_auto (&dc->coin_pub)); resume_pay_with_response (pc, http_status, TMH_RESPONSE_make_json (eproof)); @@ -453,6 +453,11 @@ pay_context_cleanup (struct TM_HandlerContext *hc) MHD_destroy_response (pc->response); pc->response = NULL; } + if (NULL != pc->chosen_exchange) + { + GNUNET_free (pc->chosen_exchange); + pc->chosen_exchange = NULL; + } GNUNET_free (pc); } @@ -850,7 +855,12 @@ MH_handler_pay (struct TMH_RequestHandler *rh, res ? "OK" : "FAILED"); return res; } - + if (NULL != pc->chosen_exchange) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Shouldn't be here. Old MHD version?\n"); + return MHD_YES; + } res = TMH_PARSE_post_json (connection, &pc->json_parse_context, upload_data, @@ -859,7 +869,8 @@ MH_handler_pay (struct TMH_RequestHandler *rh, if (GNUNET_SYSERR == res) { GNUNET_break (0); - return MHD_NO; /* error parsing JSON */ + return TMH_RESPONSE_reply_external_error (connection, + "failed to parse JSON body"); } if ((GNUNET_NO == res) || (NULL == root)) return MHD_YES; /* the POST's body has to be further fetched */ @@ -912,6 +923,7 @@ MH_handler_pay (struct TMH_RequestHandler *rh, &pubkey.eddsa_pub)) { GNUNET_break (0); + GNUNET_JSON_parse_free (spec); json_decref (root); return TMH_RESPONSE_reply_external_error (connection, "invalid merchant signature supplied"); @@ -920,7 +932,8 @@ MH_handler_pay (struct TMH_RequestHandler *rh, /* 'wire_transfer_deadline' is optional, if it is not present, generate it here; it will be timestamp plus the wire_transfer_delay supplied in config file */ - if (NULL == json_object_get (root, "wire_transfer_deadline")) + if (NULL == json_object_get (root, + "wire_transfer_deadline")) { pc->wire_transfer_deadline = GNUNET_TIME_absolute_add (pc->timestamp, wire_transfer_delay); @@ -943,6 +956,7 @@ MH_handler_pay (struct TMH_RequestHandler *rh, espec); if (GNUNET_YES != res) { + GNUNET_JSON_parse_free (spec); json_decref (root); GNUNET_break (0); return (GNUNET_NO == res) ? MHD_YES : MHD_NO; @@ -950,17 +964,18 @@ MH_handler_pay (struct TMH_RequestHandler *rh, if (pc->wire_transfer_deadline.abs_value_us < pc->refund_deadline.abs_value_us) { GNUNET_break (0); + GNUNET_JSON_parse_free (spec); json_decref (root); return TMH_RESPONSE_reply_external_error (connection, "refund deadline after wire transfer deadline"); } - } pc->coins_cnt = json_array_size (coins); if (0 == pc->coins_cnt) { + GNUNET_JSON_parse_free (spec); json_decref (root); return TMH_RESPONSE_reply_external_error (connection, "no coins given"); @@ -986,6 +1001,7 @@ MH_handler_pay (struct TMH_RequestHandler *rh, spec); if (GNUNET_YES != res) { + GNUNET_JSON_parse_free (spec); json_decref (root); GNUNET_break (0); return (GNUNET_NO == res) ? MHD_YES : MHD_NO; @@ -1005,7 +1021,8 @@ MH_handler_pay (struct TMH_RequestHandler *rh, dc->index = coins_index; dc->pc = pc; } - } + GNUNET_JSON_parse_free (spec); + } /* end of parsing of JSON upload */ pc->pending = pc->coins_cnt; /* Check if this payment attempt has already succeeded */ @@ -1016,6 +1033,7 @@ MH_handler_pay (struct TMH_RequestHandler *rh, pc)) { GNUNET_break (0); + json_decref (root); return TMH_RESPONSE_reply_internal_error (connection, "Merchant database error"); } @@ -1033,6 +1051,7 @@ MH_handler_pay (struct TMH_RequestHandler *rh, MHD_HTTP_OK, resp); MHD_destroy_response (resp); + json_decref (root); return ret; } @@ -1044,12 +1063,14 @@ MH_handler_pay (struct TMH_RequestHandler *rh, pc)) { GNUNET_break (0); + json_decref (root); return TMH_RESPONSE_reply_internal_error (connection, "Merchant database error"); } if (GNUNET_SYSERR == pc->transaction_exits) { GNUNET_break (0); + json_decref (root); return TMH_RESPONSE_reply_internal_error (connection, "Transaction ID reused with different transaction details"); } @@ -1066,6 +1087,7 @@ MH_handler_pay (struct TMH_RequestHandler *rh, &pc->amount)) { GNUNET_break (0); + json_decref (root); return TMH_RESPONSE_reply_internal_error (connection, "Merchant database error"); } diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index 6bd21aff..914b4721 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -605,6 +605,7 @@ postgres_find_transaction_by_id (void *cls, timestamp, refund_deadline, &total_amount); + GNUNET_PQ_cleanup_result (rs); } PQclear (result); return GNUNET_OK; diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c index 8b9319d7..2a172566 100644 --- a/src/backenddb/test_merchantdb.c +++ b/src/backenddb/test_merchantdb.c @@ -275,14 +275,14 @@ run (void *cls) RND_BLK (&coin_pub); deposit_proof = json_object (); GNUNET_assert (0 == - json_object_set (deposit_proof, - "test", - json_string ("backenddb test A"))); + json_object_set_new (deposit_proof, + "test", + json_string ("backenddb test A"))); transfer_proof = json_object (); GNUNET_assert (0 == - json_object_set (transfer_proof, - "test", - json_string ("backenddb test B"))); + json_object_set_new (transfer_proof, + "test", + json_string ("backenddb test B"))); FAILIF (GNUNET_OK != plugin->store_transaction (plugin->cls, transaction_id, |