summaryrefslogtreecommitdiff
path: root/toxcore/tox.c
diff options
context:
space:
mode:
authoriphydf <iphydf@users.noreply.github.com>2016-09-08 01:03:12 +0100
committeriphydf <iphydf@users.noreply.github.com>2016-09-08 01:04:46 +0100
commitca1fe7ff7d7a020421191c92f2db09f00bbd2e1c (patch)
treefb7afe609f7aa43baa9b2c274ab9c7022557d090 /toxcore/tox.c
parent159dc3b6ab0fa969722aabce70b04b3f6ec6f777 (diff)
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.
Diffstat (limited to 'toxcore/tox.c')
-rw-r--r--toxcore/tox.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/toxcore/tox.c b/toxcore/tox.c
index b155c02f..5a1103df 100644
--- a/toxcore/tox.c
+++ b/toxcore/tox.c
@@ -182,13 +182,6 @@ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error)
182 182
183 _Bool load_savedata_sk = 0, load_savedata_tox = 0; 183 _Bool load_savedata_sk = 0, load_savedata_tox = 0;
184 184
185 Logger *log = logger_new();
186
187 if (log == NULL) {
188 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_MALLOC);
189 return NULL;
190 }
191
192 if (options == NULL) { 185 if (options == NULL) {
193 m_options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT; 186 m_options.ipv6enabled = TOX_ENABLE_IPV6_DEFAULT;
194 } else { 187 } else {
@@ -266,11 +259,19 @@ Tox *tox_new(const struct Tox_Options *options, TOX_ERR_NEW *error)
266 } 259 }
267 } 260 }
268 261
262 Logger *log = logger_new();
263
264 if (log == NULL) {
265 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_MALLOC);
266 return NULL;
267 }
268
269 unsigned int m_error; 269 unsigned int m_error;
270 Messenger *m = new_messenger(log, &m_options, &m_error); 270 Messenger *m = new_messenger(log, &m_options, &m_error);
271 271
272 if (!new_groupchats(m)) { 272 if (!new_groupchats(m)) {
273 kill_messenger(m); 273 kill_messenger(m);
274 logger_kill(log);
274 275
275 if (m_error == MESSENGER_ERROR_PORT) { 276 if (m_error == MESSENGER_ERROR_PORT) {
276 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PORT_ALLOC); 277 SET_ERROR_PARAMETER(error, TOX_ERR_NEW_PORT_ALLOC);