Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
global keyset: fix memproblems
Browse files Browse the repository at this point in the history
  • Loading branch information
mpranj committed Jan 8, 2019
1 parent daccd26 commit 12acc82
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/libs/elektra/kdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ KDB * kdbOpen (Key * errorKey)
handle->modules = ksNew (0, KS_END);
if (elektraModulesInit (handle->modules, errorKey) == -1)
{
ksDel (handle->global);
ksDel (handle->modules);
elektraFree (handle);
ELEKTRA_SET_ERROR (94, errorKey, "elektraModulesInit returned with -1");
Expand All @@ -283,6 +284,7 @@ KDB * kdbOpen (Key * errorKey)
switch (elektraOpenBootstrap (handle, keys, errorKey))
{
case -1:
ksDel (handle->global);
ksDel (handle->modules);
elektraFree (handle);
ELEKTRA_SET_ERROR (40, errorKey, "could not open default backend");
Expand Down Expand Up @@ -784,7 +786,6 @@ int kdbGet (KDB * handle, KeySet * ks, Key * parentKey)

int errnosave = errno;
Key * initialParent = keyDup (parentKey);
ksClear (handle->global);

ELEKTRA_LOG ("now in new kdbGet (%s)", keyName (parentKey));

Expand All @@ -797,6 +798,8 @@ int kdbGet (KDB * handle, KeySet * ks, Key * parentKey)
goto error;
}

ksClear (handle->global);

elektraGlobalGet (handle, ks, parentKey, PREGETSTORAGE, INIT);
elektraGlobalGet (handle, ks, parentKey, PREGETSTORAGE, MAXONCE);
elektraGlobalGet (handle, ks, parentKey, PREGETSTORAGE, DEINIT);
Expand Down Expand Up @@ -916,9 +919,12 @@ int kdbGet (KDB * handle, KeySet * ks, Key * parentKey)
elektraGlobalError (handle, ks, parentKey, POSTGETSTORAGE, MAXONCE);
elektraGlobalError (handle, ks, parentKey, POSTGETSTORAGE, DEINIT);

ksClear (handle->global);
keySetName (parentKey, keyName (initialParent));
if (handle) splitUpdateFileName (split, handle, parentKey);
if (handle)
{
splitUpdateFileName (split, handle, parentKey);
if (handle->global) ksClear (handle->global);
}
keyDel (initialParent);
keyDel (oldError);
splitDel (split);
Expand Down Expand Up @@ -1321,7 +1327,7 @@ int kdbSet (KDB * handle, KeySet * ks, Key * parentKey)
elektraGlobalError (handle, ks, parentKey, POSTROLLBACK, MAXONCE);
elektraGlobalError (handle, ks, parentKey, POSTROLLBACK, DEINIT);

ksClear (handle->global);
if (handle->global) ksClear (handle->global);
keySetName (parentKey, keyName (initialParent));
keyDel (initialParent);
splitDel (split);
Expand Down

0 comments on commit 12acc82

Please sign in to comment.