diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-06-04 23:07:57 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-06-04 23:07:57 +0200 |
commit | bfd145a56ca687f0ede011a5258129d8be839742 (patch) | |
tree | 1ad15834f06584b08995eecb437aea72e1628f1e /src/backenddb | |
parent | 979e9d380d6169034f9f426a3b2b050ac4907200 (diff) | |
download | merchant-bfd145a56ca687f0ede011a5258129d8be839742.tar.gz merchant-bfd145a56ca687f0ede011a5258129d8be839742.tar.bz2 merchant-bfd145a56ca687f0ede011a5258129d8be839742.zip |
fix more leaks
Diffstat (limited to 'src/backenddb')
-rw-r--r-- | src/backenddb/plugin_merchantdb_postgres.c | 96 |
1 files changed, 39 insertions, 57 deletions
diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index 3903d172..5237e767 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -397,44 +397,35 @@ postgres_find_contract_terms_from_hash (void *cls, const struct TALER_MerchantPublicKeyP *merchant_pub) { struct PostgresClosure *pg = cls; - PGresult *result; - unsigned int i; - + enum GNUNET_PQ_QueryStatus res; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (h_contract_terms), GNUNET_PQ_query_param_auto_from_type (merchant_pub), GNUNET_PQ_query_param_end }; - - result = GNUNET_PQ_exec_prepared (pg->conn, - "find_contract_terms_from_hash", - params); - i = PQntuples (result); - if (1 < i) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Mupltiple proposal data hash the same hashcode!\n"); - return GNUNET_SYSERR; - } - - if (0 == i) - return GNUNET_NO; - struct GNUNET_PQ_ResultSpec rs[] = { TALER_PQ_result_spec_json ("contract_terms", contract_terms), GNUNET_PQ_result_spec_end }; - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - 0)) + + res = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "find_contract_terms_from_hash", + params, + rs); + if (res < 0) { GNUNET_break (0); - PQclear (result); return GNUNET_SYSERR; } - + if (1 < res) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Mupltiple proposal data hash the same hashcode!\n"); + return GNUNET_SYSERR; + } + if (0 == res) + return GNUNET_NO; return GNUNET_OK; } @@ -443,61 +434,52 @@ postgres_find_contract_terms_from_hash (void *cls, * Retrieve proposal data given its order id. * * @param cls closure - * @param contract_terms where to store the retrieved proposal data + * @param[out] contract_terms where to store the retrieved proposal data * @param order id order id used to perform the lookup * @return #GNUNET_OK on success, #GNUNET_NO if no proposal is * found, #GNUNET_SYSERR upon error */ static int postgres_find_contract_terms (void *cls, - json_t **contract_terms, - const char *order_id, - const struct TALER_MerchantPublicKeyP *merchant_pub) + json_t **contract_terms, + const char *order_id, + const struct TALER_MerchantPublicKeyP *merchant_pub) { struct PostgresClosure *pg = cls; - PGresult *result; - unsigned int i; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "finding contract term, order_id: '%s', merchant_pub: '%s'.\n", - order_id, - TALER_B2S (merchant_pub)); - + enum GNUNET_PQ_QueryStatus res; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_string (order_id), GNUNET_PQ_query_param_auto_from_type (merchant_pub), GNUNET_PQ_query_param_end }; - - result = GNUNET_PQ_exec_prepared (pg->conn, - "find_contract_terms", - params); - i = PQntuples (result); - if (1 < i) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - "Mupltiple proposal data share the same hashcode.\n"); - return GNUNET_SYSERR; - } - - if (0 == i) - return GNUNET_NO; - struct GNUNET_PQ_ResultSpec rs[] = { TALER_PQ_result_spec_json ("contract_terms", contract_terms), GNUNET_PQ_result_spec_end }; - if (GNUNET_OK != - GNUNET_PQ_extract_result (result, - rs, - 0)) + + *contract_terms = NULL; + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Finding contract term, order_id: '%s', merchant_pub: '%s'.\n", + order_id, + TALER_B2S (merchant_pub)); + res = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, + "find_contract_terms", + params, + rs); + if (res < 0) { GNUNET_break (0); - PQclear (result); return GNUNET_SYSERR; } - + if (res > 1) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Mupltiple proposal data share the same hashcode.\n"); + return GNUNET_SYSERR; + } + if (0 == res) + return GNUNET_NO; return GNUNET_OK; } |