Use popMacro() when freeing the entire macro table
authorPanu Matilainen <pmatilai@redhat.com>
Tue, 31 May 2011 07:38:17 +0000 (10:38 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Tue, 31 May 2011 08:03:43 +0000 (11:03 +0300)
- We already have a function to free macro entries, use it to
  remove code duplication

rpmio/macro.c

index edf0c7f..f5488a6 100644 (file)
@@ -1529,19 +1529,12 @@ rpmFreeMacros(rpmMacroContext mc)
     if (mc == NULL) mc = rpmGlobalMacroContext;
 
     if (mc->macroTable != NULL) {
-       int i;
-       for (i = 0; i < mc->firstFree; i++) {
-           rpmMacroEntry me;
-           while ((me = mc->macroTable[i]) != NULL) {
-               /* XXX cast to workaround const */
-               if ((mc->macroTable[i] = me->prev) == NULL)
-                   me->name = _free(me->name);
-               me->opts = _free(me->opts);
-               me->body = _free(me->body);
-               me = _free(me);
+       for (int i = 0; i < mc->firstFree; i++) {
+           while (mc->macroTable[i] != NULL) {
+               popMacro(&mc->macroTable[i]);
            }
        }
-       mc->macroTable = _free(mc->macroTable);
+       free(mc->macroTable);
     }
     memset(mc, 0, sizeof(*mc));
 }