fix memory leaks (#5050)

This commit is contained in:
Christian Grothoff 2017-06-04 12:07:53 +02:00
parent ad850ce0a9
commit 59fd83b731
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
4 changed files with 58 additions and 14 deletions

1
.gitignore vendored
View File

@ -84,3 +84,4 @@ doc/manual/manual.toc
doc/manual/manual.tp
doc/manual/manual.vr
contrib/taler-exchange.tag
doxygen-doc/

View File

@ -13,6 +13,8 @@ ACLOCAL_AMFLAGS = -I m4
EXTRA_DIST = \
AUTHORS \
contrib/coverage.sh \
contrib/gnunet.tag \
contrib/microhttpd.tag \
Doxyfile
app:

View File

@ -361,6 +361,7 @@ handle_admin_add_incoming (struct TALER_FAKEBANK_Handle *h,
(json_int_t) t->serial_id);
json_str = json_dumps (json,
JSON_INDENT(2));
json_decref (json);
if (NULL == json_str)
{
GNUNET_break (0);

View File

@ -409,11 +409,42 @@ parse_reserve_history (struct TALER_EXCHANGE_Handle *exchange,
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
return GNUNET_OK;
}
/**
* Free memory (potentially) allocated by #parse_reserve_history().
*
* @param rhistory result to free
* @param len number of entries in @a rhistory
*/
static void
free_rhistory (struct TALER_EXCHANGE_ReserveHistory *rhistory,
unsigned int len)
{
for (unsigned int i=0;i<len;i++)
{
switch (rhistory[i].type)
{
case TALER_EXCHANGE_RTT_DEPOSIT:
GNUNET_free_non_null (rhistory[i].details.in_details.wire_reference);
if (NULL != rhistory[i].details.in_details.sender_account_details)
json_decref (rhistory[i].details.in_details.sender_account_details);
break;
case TALER_EXCHANGE_RTT_WITHDRAWAL:
break;
case TALER_EXCHANGE_RTT_PAYBACK:
break;
case TALER_EXCHANGE_RTT_CLOSE:
if (NULL != rhistory[i].details.close_details.receiver_account_details)
json_decref (rhistory[i].details.close_details.receiver_account_details);
break;
}
}
}
/**
* Function called when we're done processing the
* HTTP /reserve/status request.
@ -468,6 +499,7 @@ handle_reserve_status_finished (void *cls,
{
struct TALER_EXCHANGE_ReserveHistory rhistory[len];
memset (rhistory, 0, sizeof (rhistory));
if (GNUNET_OK !=
parse_reserve_history (rsh->exchange,
history,
@ -479,17 +511,18 @@ handle_reserve_status_finished (void *cls,
{
GNUNET_break_op (0);
response_code = 0;
break;
}
if (0 !=
if ( (0 != response_code) &&
(0 !=
TALER_amount_cmp (&balance_from_history,
&balance))
&balance)) )
{
/* exchange cannot add up balances!? */
GNUNET_break_op (0);
response_code = 0;
break;
}
if (0 != response_code)
{
rsh->cb (rsh->cb_cls,
response_code,
TALER_EC_NONE,
@ -499,6 +532,9 @@ handle_reserve_status_finished (void *cls,
rhistory);
rsh->cb = NULL;
}
free_rhistory (rhistory,
len);
}
}
break;
case MHD_HTTP_BAD_REQUEST:
@ -796,8 +832,12 @@ reserve_withdraw_payment_required (struct TALER_EXCHANGE_ReserveWithdrawHandle *
rhistory))
{
GNUNET_break_op (0);
free_rhistory (rhistory,
len);
return GNUNET_SYSERR;
}
free_rhistory (rhistory,
len);
}
if (0 !=