Browse Source

Fix mem leak caused by electrum_txhistory_loop.

blackjok3r
Artem Pikulin 6 years ago
parent
commit
14097b0bcc
  1. 18
      iguana/exchanges/LP_etomic.c
  2. 13
      iguana/exchanges/LP_socket.c

18
iguana/exchanges/LP_etomic.c

@ -844,8 +844,10 @@ void LP_etomic_txhistory_loop(void *_coin)
result = eth_tx_history_etherscan(coin->smartaddr);
if (result) {
json = cJSON_Parse(result);
if (json && is_cJSON_Array(jobj(json, "result"))) {
LP_etomic_process_tx_history_json(coin, jobj(json, "result"));
if (json) {
if (is_cJSON_Array(jobj(json, "result"))) {
LP_etomic_process_tx_history_json(coin, jobj(json, "result"));
}
free_json(json);
}
free(result);
@ -856,8 +858,10 @@ void LP_etomic_txhistory_loop(void *_coin)
result = internal_eth_tx_history_etherscan(coin->smartaddr);
if (result) {
json = cJSON_Parse(result);
if (json && is_cJSON_Array(jobj(json, "result"))) {
LP_etomic_process_tx_history_json(coin, jobj(json, "result"));
if (json) {
if (is_cJSON_Array(jobj(json, "result"))) {
LP_etomic_process_tx_history_json(coin, jobj(json, "result"));
}
free_json(json);
}
free(result);
@ -866,8 +870,10 @@ void LP_etomic_txhistory_loop(void *_coin)
result = erc20_tx_history_etherscan(coin->smartaddr, coin->etomic);
if (result) {
json = cJSON_Parse(result);
if (json && is_cJSON_Array(jobj(json, "result"))) {
LP_etomic_process_tx_history_json(coin, jobj(json, "result"));
if (json) {
if (is_cJSON_Array(jobj(json, "result"))) {
LP_etomic_process_tx_history_json(coin, jobj(json, "result"));
}
free_json(json);
}
free(result);

13
iguana/exchanges/LP_socket.c

@ -1237,8 +1237,10 @@ void LP_electrum_get_tx_until_success(struct iguana_info *coin, char *tx_hash, c
electrum_jsonarg(coin->symbol, coin->electrum, res, "blockchain.transaction.get", params,
ELECTRUM_TIMEOUT);
if (jobj(*res, "error") != NULL) {
printf("Error getting electrum tx %s %s %s\n", coin->symbol, jstri(params, 0), jprint(*res, 1));
char *msg = jprint(*res, 1);
printf("Error getting electrum tx %s %s %s\n", coin->symbol, jstri(params, 0), msg);
*res = cJSON_CreateObject();
free(msg);
sleep(5);
continue;
} else {
@ -1290,16 +1292,16 @@ void LP_electrum_txhistory_loop(void *_coin)
ELECTRUM_TIMEOUT);
}
if (jobj(history, "error") != NULL) {
printf("Error getting electrum history of coin %s %s\n", coin->symbol, jprint(history, 1));
char *msg = jprint(history, 1);
printf("Error getting electrum history of coin %s %s\n", coin->symbol, msg);
free(msg);
sleep(10);
continue;
}
int history_size = cJSON_GetArraySize(history);
for (int i = history_size - 1; i >= 0; i--) {
cJSON *history_item = jitem(history, i);
cJSON *tx_item = cJSON_CreateObject();
char *tx_hash = jstr(history_item, "tx_hash");
LP_electrum_get_tx_until_success(coin, tx_hash, &tx_item);
struct LP_tx_history_item *iter;
int found = 0;
int confirmed = 0;
@ -1325,7 +1327,8 @@ void LP_electrum_txhistory_loop(void *_coin)
} else {
continue;
}
cJSON *tx_item = cJSON_CreateObject();
LP_electrum_get_tx_until_success(coin, tx_hash, &tx_item);
if (!found) {
strcpy(item->txid, jstr(tx_item, "txid"));
// receive by default, but if at least 1 vin contains our address the category is send

Loading…
Cancel
Save