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

Commit

Permalink
Revert "avoid unnecessary keyDel"
Browse files Browse the repository at this point in the history
This reverts commit f648ce4.
  • Loading branch information
Klemens Böswirth committed Aug 26, 2021
1 parent f648ce4 commit 74012fa
Show file tree
Hide file tree
Showing 31 changed files with 82 additions and 97 deletions.
7 changes: 1 addition & 6 deletions src/bindings/cpp/include/key.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1640,12 +1640,7 @@ inline int Key::del ()
if (key)
{
operator-- ();
ssize_t rc = getReferenceCounter ();
if (rc == 0)
{
return ckdb::keyDel (key);
}
return static_cast<int> (rc);
return ckdb::keyDel (key);
}
return -1;
}
Expand Down
6 changes: 2 additions & 4 deletions src/bindings/glib/gelektra-key.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ static void gelektra_key_finalize (GObject * object)
{
GElektraKey * self = GELEKTRA_KEY (object);

if (keyDecRef (self->key) == 0)
{
keyDel (self->key);
}
keyDecRef (self->key);
keyDel (self->key);

/* Always chain up to the parent class; as with dispose(), finalize()
* is guaranteed to exist on the parent's class virtual function table
Expand Down
6 changes: 2 additions & 4 deletions src/libs/elektra/backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,11 +465,9 @@ int backendClose (Backend * backend, Key * errorKey)

if (backend->mountpoint)
{
keyDecRef (backend->mountpoint);
keySetName (errorKey, keyName (backend->mountpoint));
if (keyDecRef (backend->mountpoint) == 0)
{
keyDel (backend->mountpoint);
}
keyDel (backend->mountpoint);
}

for (int i = 0; i < NR_OF_PLUGINS; ++i)
Expand Down
17 changes: 4 additions & 13 deletions src/libs/elektra/kdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,7 @@ KeySet * ksRenameKeys (KeySet * config, const char * name)
root = ksNext (config);
rootSize = keyGetNameSize (root);

Key * r = ksLookup (config, root, KDB_O_POP);
if (keyGetRef (r) == 0)
{
keyDel (r);
}
keyDel (ksLookup (config, root, KDB_O_POP));

KeySet * newConfig = ksNew (ksGetSize (config), KS_END);
if (rootSize == -1) return newConfig;
Expand All @@ -179,10 +175,7 @@ KeySet * ksRenameKeys (KeySet * config, const char * name)
keySetName (dupKey, name);
keyAddName (dupKey, keyName (cur) + rootSize - 1);
ksAppendKey (newConfig, dupKey);
if (keyGetRef (cur) == 0)
{
keyDel (cur);
}
keyDel (cur);
}

return newConfig;
Expand Down Expand Up @@ -336,10 +329,8 @@ static int ensureContractMountGlobal (KDB * handle, KeySet * contract, Key * par

// we ned to delete cur separately, because it was ksCut() from contract
// we also need to decrement the ref count, because it was incremented above
if (keyDecRef (cur) == 0)
{
keyDel (cur);
}
keyDecRef (cur);
keyDel (cur);

if (ret == ELEKTRA_PLUGIN_STATUS_ERROR)
{
Expand Down
2 changes: 0 additions & 2 deletions src/libs/elektra/key.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "kdbprivate.h"
#include <kdbassert.h>

// #include <signal.h>

/**
* @defgroup key Key
Expand Down Expand Up @@ -504,7 +503,6 @@ int keyDel (Key * key)

if (key->ksReference > 0)
{
// raise(SIGTRAP);
return key->ksReference;
}

Expand Down
5 changes: 1 addition & 4 deletions src/libs/elektra/keymeta.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,10 +540,7 @@ ssize_t keySetMeta (Key * key, const char * metaName, const char * newMetaString
if (ret)
{
/*It was already there, so lets drop that one*/
if (keyGetRef (ret) == 0)
{
keyDel (ret);
}
keyDel (ret);
key->flags |= KEY_FLAG_SYNC;
}
}
Expand Down
13 changes: 5 additions & 8 deletions src/libs/elektra/keyset.c
Original file line number Diff line number Diff line change
Expand Up @@ -778,10 +778,8 @@ ssize_t ksAppendKey (KeySet * ks, Key * toAppend)
}

/* Pop the key in the result */
if (keyDecRef (ks->array[result]) == 0)
{
keyDel (ks->array[result]);
}
keyDecRef (ks->array[result]);
keyDel (ks->array[result]);

/* And use the other one instead */
keyIncRef (toAppend);
Expand Down Expand Up @@ -2634,11 +2632,10 @@ int ksClose (KeySet * ks)
ksRewind (ks);
while ((k = ksNext (ks)) != 0)
{
if (keyDecRef (k) == 0)
{
keyDel (k);
}
keyDecRef (k);
keyDel (k);
}

if (ks->array && !test_bit (ks->flags, KS_FLAG_MMAP_ARRAY))
{
elektraFree (ks->array);
Expand Down
1 change: 1 addition & 0 deletions src/libs/elektra/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ int elektraMountGlobalsLoadPlugin (Plugin ** plugin, KeySet * referencePlugins,
refKey = keyNew ("/", KEY_BINARY, KEY_SIZE, sizeof (Plugin *), KEY_VALUE, &(*plugin), KEY_END);
keyAddBaseName (refKey, keyString (cur));
ksAppendKey (referencePlugins, refKey);
keyDel (refKey);
}

keyCopyAllMeta (errorKey, openKey);
Expand Down
7 changes: 7 additions & 0 deletions src/libs/elektra/split.c
Original file line number Diff line number Diff line change
Expand Up @@ -883,48 +883,55 @@ void splitCacheStoreState (KDB * handle, Split * split, KeySet * global, Key * p
ksAppendKey (global, key);
ELEKTRA_LOG_DEBUG (">>>> STORING key: %s, string: %s, strlen: %ld, valSize: %ld", keyName (key), keyString (key),
strlen (keyString (key)), keyGetValueSize (key));
keyDel (key);

key = keyNew (name, KEY_END);
keyAddBaseName (key, "splitParentValue");
keySetString (key, keyString (split->parents[i]));
ksAppendKey (global, key);
ELEKTRA_LOG_DEBUG (">>>> STORING key: %s, string: %s, strlen: %ld, valSize: %ld", keyName (key), keyString (key),
strlen (keyString (key)), keyGetValueSize (key));
keyDel (key);

key = keyNew (name, KEY_END);
keyAddBaseName (key, "specsize");
keySetBinary (key, &(split->handles[i]->specsize), sizeof (ssize_t));
ksAppendKey (global, key);
ELEKTRA_LOG_DEBUG (">>>> STORING key: %s, string: %s, strlen: %ld, valSize: %ld", keyName (key), keyString (key),
strlen (keyString (key)), keyGetValueSize (key));
keyDel (key);

key = keyNew (name, KEY_END);
keyAddBaseName (key, "dirsize");
keySetBinary (key, &(split->handles[i]->dirsize), sizeof (ssize_t));
ksAppendKey (global, key);
ELEKTRA_LOG_DEBUG (">>>> STORING key: %s, string: %s, strlen: %ld, valSize: %ld", keyName (key), keyString (key),
strlen (keyString (key)), keyGetValueSize (key));
keyDel (key);

key = keyNew (name, KEY_END);
keyAddBaseName (key, "usersize");
keySetBinary (key, &(split->handles[i]->usersize), sizeof (ssize_t));
ksAppendKey (global, key);
ELEKTRA_LOG_DEBUG (">>>> STORING key: %s, string: %s, strlen: %ld, valSize: %ld", keyName (key), keyString (key),
strlen (keyString (key)), keyGetValueSize (key));
keyDel (key);

key = keyNew (name, KEY_END);
keyAddBaseName (key, "systemsize");
keySetBinary (key, &(split->handles[i]->systemsize), sizeof (ssize_t));
ksAppendKey (global, key);
ELEKTRA_LOG_DEBUG (">>>> STORING key: %s, string: %s, strlen: %ld, valSize: %ld", keyName (key), keyString (key),
strlen (keyString (key)), keyGetValueSize (key));
keyDel (key);

key = keyNew (name, KEY_END);
keyAddBaseName (key, "syncbits");
keySetBinary (key, &(split->syncbits[i]), sizeof (splitflag_t));
ksAppendKey (global, key);
ELEKTRA_LOG_DEBUG (">>>> STORING key: %s, string: %s, strlen: %ld, valSize: %ld", keyName (key), keyString (key),
strlen (keyString (key)), keyGetValueSize (key));
keyDel (key);

elektraFree (name);
}
Expand Down
4 changes: 4 additions & 0 deletions src/libs/merge/kdbmerge.c
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,7 @@ static int handleArrays (KeySet * ourSet, KeySet * theirSet, KeySet * baseSet, K
if (baseArray == NULL)
{
ELEKTRA_SET_INTERNAL_ERROR (informationKey, "Could not convert `base` KeySet into char[] for LibGit.");
keyDel (checkedKey);
ksDel (toAppend);
return -1;
}
Expand All @@ -857,6 +858,7 @@ static int handleArrays (KeySet * ourSet, KeySet * theirSet, KeySet * baseSet, K
{
ELEKTRA_SET_INTERNAL_ERROR (informationKey, "Could not convert `our` KeySet into char[] for LibGit.");
elektraFree (baseArray);
keyDel (checkedKey);
ksDel (toAppend);
return -1;
}
Expand All @@ -866,6 +868,7 @@ static int handleArrays (KeySet * ourSet, KeySet * theirSet, KeySet * baseSet, K
ELEKTRA_SET_INTERNAL_ERROR (informationKey, "Could not convert `their` KeySet into char[] for LibGit.");
elektraFree (ourArray);
elektraFree (baseArray);
keyDel (checkedKey);
ksDel (toAppend);
return -1;
}
Expand Down Expand Up @@ -919,6 +922,7 @@ static int handleArrays (KeySet * ourSet, KeySet * theirSet, KeySet * baseSet, K
elektraFree (baseArray);
keyDel (keyInOur);
keyDel (keyInTheir);
keyDel (checkedKey);
}
}
if (toAppend != NULL)
Expand Down
2 changes: 1 addition & 1 deletion src/libs/meta/meta.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ int elektraSortTopology (KeySet * ks, Key ** array)
{
cur = localArray[j];
KeySet * deps = elektraMetaArrayToKS (cur, "dep");
ksLookupByName (deps, "meta:/dep", KDB_O_POP);
keyDel (ksLookupByName (deps, "meta:/dep", KDB_O_POP));
Key * tmpDep;
switch (ksGetSize (deps))
{
Expand Down
10 changes: 10 additions & 0 deletions src/libs/opts/opts.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ bool processSpec (struct Specification * spec, KeySet * ks, Key * specParent, Ke
keyName (parent));
return false;
}
keyDel (parent);
}
}

Expand Down Expand Up @@ -846,6 +847,7 @@ bool processShortOptSpec (struct Specification * spec, struct OptionData * optio
"The option '-%c' has already been specified for the key '%s'. Additional key: %s",
shortOpt, keyGetMetaString (existing, "key"), keyName (key));
keyDel (shortOptSpec);
keyDel (existing);
return false;
}

Expand Down Expand Up @@ -1003,6 +1005,7 @@ bool processEnvVars (KeySet * usedEnvVars, Key * specKey, Key ** keyWithOpt, Key
errorKey, "The environment variable '%s' has already been specified for the key '%s'. Additional key: %s",
envVar, keyGetMetaString (existing, "key"), keyName (specKey));
elektraFree (envsLinePart);
keyDel (existing);
keyDel (envVarKey);
ksDel (envVars);
return false;
Expand Down Expand Up @@ -1602,6 +1605,7 @@ bool parseShortOptions (Key * command, KeySet * optionsSpec, KeySet * options, i
{
ELEKTRA_SET_VALIDATION_SEMANTIC_ERRORF (errorKey, "Unknown short option: -%c", keyBaseName (shortOpt)[0]);
keyDel (shortOpt);
keyDel (optSpec);
return false;
}

Expand All @@ -1621,8 +1625,10 @@ bool parseShortOptions (Key * command, KeySet * optionsSpec, KeySet * options, i
{
ELEKTRA_SET_VALIDATION_SEMANTIC_ERRORF (errorKey, "This option cannot be repeated: -%c", keyBaseName (shortOpt)[0]);
keyDel (shortOpt);
keyDel (optSpec);
return false;
}
keyDel (optSpec);

bool last = false;
if (elektraStrCmp (hasArg, "required") == 0)
Expand All @@ -1634,6 +1640,7 @@ bool parseShortOptions (Key * command, KeySet * optionsSpec, KeySet * options, i
ELEKTRA_SET_VALIDATION_SEMANTIC_ERRORF (errorKey, "Missing argument for short option: -%c",
keyBaseName (shortOpt)[0]);
keyDel (shortOpt);
keyDel (option);
return false;
}
// use next as arg and skip
Expand Down Expand Up @@ -1711,14 +1718,17 @@ bool parseLongOption (Key * command, KeySet * optionsSpec, KeySet * options, int
{
ELEKTRA_SET_VALIDATION_SEMANTIC_ERRORF (errorKey, "This option cannot be repeated: --%s", keyBaseName (longOpt));
keyDel (longOpt);
keyDel (optSpec);
return false;
}
else if (keyGetMetaString (option, "short") != NULL)
{
keyDel (longOpt);
keyDel (optSpec);
// short option found already ignore long version
return true;
}
keyDel (optSpec);

if (elektraStrCmp (hasArg, "required") == 0)
{
Expand Down
4 changes: 2 additions & 2 deletions src/libs/pluginprocess/tests/testlib_pluginprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ static void test_reservedParentKeyName (void)
output_warnings (parentKey);
output_error (parentKey);

// TODO: always in ks? keyDel (parentKey);
keyDel (parentKey);
ksDel (ks);
ksDel (conf);
elektraFree (plugin);
Expand Down Expand Up @@ -328,7 +328,7 @@ static void test_childAddingParentKey (void)
output_warnings (parentKey);
output_error (parentKey);

// TODO: always in ks? keyDel (parentKey);
keyDel (parentKey);
ksDel (ks);
ksDel (conf);
elektraFree (plugin);
Expand Down
1 change: 1 addition & 0 deletions src/plugins/cache/testmod_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ static void test_cacheNonBackendKeys (void)
succeed_if (freshResult == 0, "key was persisted/cached, even though it was not committed");
ksDel (freshConf);

keyDel (doNotCache);
keyDel (key);
ksDel (conf);
kdbClose (handle, 0);
Expand Down
6 changes: 1 addition & 5 deletions src/plugins/csvstorage/csvstorage.c
Original file line number Diff line number Diff line change
Expand Up @@ -753,11 +753,7 @@ int elektraCsvstorageSet (Plugin * handle, KeySet * returned, Key * parentKey)
{
exportKS = ksCut (config, exportKey);
ksAppend (config, exportKS);
Key * k = ksLookup (exportKS, exportKey, KDB_O_POP);
if (keyGetRef (k) == 0)
{
keyDel (k);
}
keyDel (ksLookup (exportKS, exportKey, KDB_O_POP));
ksRewind (exportKS);
}
short useHeader = 0;
Expand Down
5 changes: 1 addition & 4 deletions src/plugins/keytometa/keytometa.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,7 @@ void removeKeyFromResult (Key * convertKey, Key * target, KeySet * orig)
*/
keySetMeta (convertKey, CONVERT_TARGET, keyName (target));
Key * key = ksLookup (orig, convertKey, KDB_O_POP);
if (keyGetRef (key) == 0)
{
keyDel (key);
}
keyDel (key);
}

static void flushConvertedKeys (Key * target, KeySet * converted, KeySet * orig)
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/macaddr/testmod_macaddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ static void testAddressesSetGet (const char * keyValue, unsigned long long longV
convertLong (intChar, longValue);
succeed_if (!strcmp (getKeyString (testKs, "user:/tests/mac/addr"), intChar), "error");
succeed_if (!strcmp (keyString (keyGetMeta (key, "origvalue")), keyValue), "error");
keyDel (key);
ksDel (testKs);
}

Expand Down Expand Up @@ -144,6 +145,7 @@ static void testRestoreValue (void)
getKeyString (testKs, "user:/tests/mac/addr");
setKey (testKs);
succeed_if (!strcmp (keyString (key), val), "error");
keyDel (key);
ksDel (testKs);
}

Expand Down
1 change: 1 addition & 0 deletions src/plugins/passwd/passwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ static struct passwd * KStoPasswd (KeySet * ks, SortBy index)
pwd->pw_passwd = "";
else
pwd->pw_passwd = (char *) keyString (found);
keyDel (parent);
keyDel (lookup);
return pwd;
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/process/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static int validPluginName (Key * pluginNameKey, Key * errorKey)
static void cleanup (Process * process, Key * errorKey)
{
if (process->plugin) elektraInvokeClose (process->plugin, errorKey);
if (process->pluginName && keyGetRef (process->pluginName) == 0) keyDel (process->pluginName);
if (process->pluginName) keyDel (process->pluginName);
ksDel (process->pluginConfig);
elektraFree (process);
}
Expand Down
Loading

0 comments on commit 74012fa

Please sign in to comment.