diff options
author | Vincent Sanders <vince@netsurf-browser.org> | 2018-05-18 09:56:16 +0100 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2018-05-18 10:02:03 +0100 |
commit | 7c3da95a07f0d21860e6803567b0603127c517c1 (patch) | |
tree | 531aba226bee2282061d6adf90b70aaadbeb77ee /utils/messages.c | |
parent | 216fb88f58227f94e87d9e9926b599161a8e65bb (diff) | |
download | netsurf-7c3da95a07f0d21860e6803567b0603127c517c1.tar.gz netsurf-7c3da95a07f0d21860e6803567b0603127c517c1.tar.bz2 |
Resolve resource leak on error (coverity issue 1390560)
Diffstat (limited to 'utils/messages.c')
-rw-r--r-- | utils/messages.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/utils/messages.c b/utils/messages.c index e1e61201f..2e22cc731 100644 --- a/utils/messages.c +++ b/utils/messages.c @@ -57,16 +57,16 @@ static nserror messages_load_ctx(const char *path, struct hash_table **ctx) { struct hash_table *nctx; /* new context */ nserror res; - - if (*ctx == NULL) { - nctx = hash_create(HASH_SIZE); - } else { + + if (*ctx != NULL) { /** * \note The passed hash is not copied here so this * updates in place. */ - nctx = *ctx; + return hash_add_file(*ctx, path); } + + nctx = hash_create(HASH_SIZE); if (nctx == NULL) { NSLOG(netsurf, INFO, "Unable to create hash table for messages file %s", @@ -74,10 +74,11 @@ static nserror messages_load_ctx(const char *path, struct hash_table **ctx) return NSERROR_NOMEM; } - res = hash_add_file(nctx, path); if (res == NSERROR_OK) { *ctx = nctx; + } else { + hash_destroy(nctx); } return res; @@ -337,4 +338,3 @@ void messages_destroy(void) messages_destroy_ctx(messages_hash); messages_hash = NULL; } - |