ini: also del oldSectionKey
@@ -1284,7 +1284,6 @@ static int iniWriteKeySet (FILE * fh, Key * parentKey, KeySet * returned, IniPlu
sectionKey = keyNew (keyString (parentMeta), KEY_END);
if (!keyIsBelow (oldSectionKey, sectionKey))
{
- removeSectionKey = 1;
if (keyIsBelow (parentKey, sectionKey))
{
char * name = getIniName (parentKey, sectionKey);
@@ -1315,6 +1314,15 @@ static int iniWriteKeySet (FILE * fh, Key * parentKey, KeySet * returned, IniPlu
else
fprintf (fh, "[]\n");
}
+
+ if (removeSectionKey)
+ {
+ // remove previous sectionKey
+ keyDel (oldSectionKey);
+ }
+
+ // mark allocated sectionKey to be freed later
+ removeSectionKey = 1;
}
else
{
