Skip to content

Commit

Permalink
Merge pull request #1946 from chu11/issue1944
Browse files Browse the repository at this point in the history
modules/kvs/kvstxn: Fix mem-leak in kvs merge
  • Loading branch information
garlick authored Jan 23, 2019
2 parents d3ee8a1 + ff7a4a2 commit 34ed5f6
Showing 1 changed file with 20 additions and 55 deletions.
75 changes: 20 additions & 55 deletions src/modules/kvs/kvstxn.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,47 +90,39 @@ static kvstxn_t *kvstxn_create (kvstxn_mgr_t *ktm,
int flags)
{
kvstxn_t *kt;
int saved_errno;

if (!(kt = calloc (1, sizeof (*kt)))) {
saved_errno = ENOMEM;
goto error;
}
if (!(kt->ops = json_copy (ops))) {
saved_errno = ENOMEM;
goto error;
if (!(kt = calloc (1, sizeof (*kt))))
goto error_enomem;
if (ops) {
if (!(kt->ops = json_copy (ops)))
goto error_enomem;
}
if (!(kt->names = json_array ())) {
saved_errno = ENOMEM;
goto error;
else {
if (!(kt->ops = json_array ()))
goto error_enomem;
}
if (!(kt->names = json_array ()))
goto error_enomem;
if (name) {
json_t *s;
if (!(s = json_string (name))) {
saved_errno = ENOMEM;
goto error;
}
if (!(s = json_string (name)))
goto error_enomem;
if (json_array_append_new (kt->names, s) < 0) {
json_decref (s);
saved_errno = ENOMEM;
goto error;
goto error_enomem;
}
}
kt->flags = flags;
if (!(kt->missing_refs_list = zlist_new ())) {
saved_errno = ENOMEM;
goto error;
}
if (!(kt->dirty_cache_entries_list = zlist_new ())) {
saved_errno = ENOMEM;
goto error;
}
if (!(kt->missing_refs_list = zlist_new ()))
goto error_enomem;
if (!(kt->dirty_cache_entries_list = zlist_new ()))
goto error_enomem;
kt->ktm = ktm;
kt->state = KVSTXN_STATE_INIT;
return kt;
error:
error_enomem:
kvstxn_destroy (kt);
errno = saved_errno;
errno = ENOMEM;
return NULL;
}

Expand Down Expand Up @@ -1228,33 +1220,6 @@ static int kvstxn_merge (kvstxn_t *dest, kvstxn_t *src)
return 1;
}

static kvstxn_t *kvstxn_create_empty (kvstxn_mgr_t *ktm, int flags)
{
kvstxn_t *ktnew;

if (!(ktnew = calloc (1, sizeof (*ktnew))))
goto error_enomem;
if (!(ktnew->ops = json_array ()))
goto error_enomem;
if (!(ktnew->keys = json_array ()))
goto error_enomem;
if (!(ktnew->names = json_array ()))
goto error_enomem;
if (!(ktnew->missing_refs_list = zlist_new ()))
goto error_enomem;
if (!(ktnew->dirty_cache_entries_list = zlist_new ()))
goto error_enomem;
ktnew->flags = flags;
ktnew->ktm = ktm;
ktnew->state = KVSTXN_STATE_INIT;
return ktnew;

error_enomem:
kvstxn_destroy (ktnew);
errno = ENOMEM;
return NULL;
}

/* Merge ready transactions that are mergeable, where merging consists
* creating a new kvstxn_t, and merging the other transactions in the
* ready queue and appending their ops/names to the new transaction.
Expand Down Expand Up @@ -1297,7 +1262,7 @@ int kvstxn_mgr_merge_ready_transactions (kvstxn_mgr_t *ktm)
|| (first->flags != second->flags))
return 0;

if (!(new = kvstxn_create_empty (ktm, first->flags)))
if (!(new = kvstxn_create (ktm, NULL, NULL, first->flags)))
return -1;
new->internal_flags |= KVSTXN_MERGED;

Expand Down

0 comments on commit 34ed5f6

Please sign in to comment.