Fix memory leaks.
This commit is contained in:
parent
d5135c00bc
commit
bcf565b352
@ -290,25 +290,24 @@ twc_cmd_friend_add_cb(void *data, enum t_twc_dns_rc rc, const uint8_t *tox_id)
|
|||||||
weechat_printf(profile->buffer,
|
weechat_printf(profile->buffer,
|
||||||
"%sUnsupported Tox DNS version in reply.",
|
"%sUnsupported Tox DNS version in reply.",
|
||||||
weechat_prefix("error"));
|
weechat_prefix("error"));
|
||||||
return;
|
goto err;
|
||||||
case TWC_DNS_RC_ERROR:
|
case TWC_DNS_RC_ERROR:
|
||||||
weechat_printf(profile->buffer, "%sCould not resolve Tox ID.",
|
weechat_printf(profile->buffer, "%sCould not resolve Tox ID.",
|
||||||
weechat_prefix("error"));
|
weechat_prefix("error"));
|
||||||
return;
|
goto err;
|
||||||
case TWC_DNS_RC_EINVAL:
|
case TWC_DNS_RC_EINVAL:
|
||||||
weechat_printf(profile->buffer, "%sInvalid Tox DNS ID.",
|
weechat_printf(profile->buffer, "%sInvalid Tox DNS ID.",
|
||||||
weechat_prefix("error"));
|
weechat_prefix("error"));
|
||||||
return;
|
goto err;
|
||||||
default:
|
default:
|
||||||
weechat_printf(profile->buffer,
|
weechat_printf(profile->buffer,
|
||||||
"%sUnknown error resolving Tox ID (%d).",
|
"%sUnknown error resolving Tox ID (%d).",
|
||||||
weechat_prefix("error"), rc);
|
weechat_prefix("error"), rc);
|
||||||
return;
|
goto err;
|
||||||
}
|
}
|
||||||
twc_bin2hex(tox_id, TOX_ADDRESS_SIZE, toxid);
|
twc_bin2hex(tox_id, TOX_ADDRESS_SIZE, toxid);
|
||||||
toxid[TOX_ADDRESS_SIZE * 2] = 0;
|
toxid[TOX_ADDRESS_SIZE * 2] = 0;
|
||||||
weechat_printf(profile->buffer, "Resolved tox dns id '%s' to %s", name, toxid);
|
weechat_printf(profile->buffer, "Resolved tox dns id '%s' to %s", name, toxid);
|
||||||
free(name);
|
|
||||||
|
|
||||||
/* -force to delete friend before sending a new friend request */
|
/* -force to delete friend before sending a new friend request */
|
||||||
if (force)
|
if (force)
|
||||||
@ -329,7 +328,7 @@ twc_cmd_friend_add_cb(void *data, enum t_twc_dns_rc rc, const uint8_t *tox_id)
|
|||||||
"%scould not remove friend; please remove "
|
"%scould not remove friend; please remove "
|
||||||
"manually before resending friend request",
|
"manually before resending friend request",
|
||||||
weechat_prefix("error"));
|
weechat_prefix("error"));
|
||||||
return;
|
goto err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -382,6 +381,9 @@ twc_cmd_friend_add_cb(void *data, enum t_twc_dns_rc rc, const uint8_t *tox_id)
|
|||||||
weechat_prefix("error"), err);
|
weechat_prefix("error"), err);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
err:
|
||||||
|
free(name);
|
||||||
|
free(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -461,14 +463,19 @@ twc_cmd_friend(void *data, struct t_gui_buffer *buffer,
|
|||||||
hex_id = &hex_id[4];
|
hex_id = &hex_id[4];
|
||||||
|
|
||||||
char *dns_name = strdup(hex_id);
|
char *dns_name = strdup(hex_id);
|
||||||
if (!dns_name)
|
char *msg = strdup(message);
|
||||||
|
if (!dns_name || !msg)
|
||||||
{
|
{
|
||||||
weechat_printf(profile->buffer,
|
weechat_printf(profile->buffer,
|
||||||
"%sMemory allocation error.",
|
"%sMemory allocation error.",
|
||||||
weechat_prefix("error"));
|
weechat_prefix("error"));
|
||||||
|
if (msg)
|
||||||
|
free(msg);
|
||||||
|
if (dns_name)
|
||||||
|
free(dns_name);
|
||||||
return WEECHAT_RC_OK;
|
return WEECHAT_RC_OK;
|
||||||
}
|
}
|
||||||
t_twc_friend_add_data data = { force, profile, dns_name, message };
|
t_twc_friend_add_data data = { force, profile, dns_name, msg };
|
||||||
uint8_t address[TOX_ADDRESS_SIZE];
|
uint8_t address[TOX_ADDRESS_SIZE];
|
||||||
|
|
||||||
if (strlen(hex_id) != TOX_ADDRESS_SIZE * 2)
|
if (strlen(hex_id) != TOX_ADDRESS_SIZE * 2)
|
||||||
|
Loading…
Reference in New Issue
Block a user