Fix memory leak on error paths in tox_new.

We didn't need to create the logger before all the validations. There is only
one error path where we need to free the logger.
This commit is contained in:
iphydf 2016-09-08 01:03:12 +01:00
parent 159dc3b6ab
commit ca1fe7ff7d
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9

View File

@ -182,13 +182,6 @@ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error)
_Bool load_savedata_sk = 0, load_savedata_tox = 0; _Bool load_savedata_sk = 0, load_savedata_tox = 0;
Logger *log = logger_new();
if (log == NULL) {
SET_ERROR_PARAMETER(error, TOX_ERR_NEW_MALLOC);
return NULL;
}
if (options == NULL) { if (options == NULL) {
m_options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; m_options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT;
} else { } else {
@ -266,11 +259,19 @@ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error)
} }
} }
Logger *log = logger_new();
if (log == NULL) {
SET_ERROR_PARAMETER(error, TOX_ERR_NEW_MALLOC);
return NULL;
}
unsigned int m_error; unsigned int m_error;
Messenger *m = new_messenger(log, &m_options, &m_error); Messenger *m = new_messenger(log, &m_options, &m_error);
if (!new_groupchats(m)) { if (!new_groupchats(m)) {
kill_messenger(m); kill_messenger(m);
logger_kill(log);
if (m_error == MESSENGER_ERROR_PORT) { if (m_error == MESSENGER_ERROR_PORT) {
SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PORT_ALLOC); SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PORT_ALLOC);