Eliminate unnecessary fsm->path/opath shuffle on backup renaming
authorPanu Matilainen <pmatilai@redhat.com>
Mon, 16 Jan 2012 10:28:52 +0000 (12:28 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Mon, 16 Jan 2012 10:43:51 +0000 (12:43 +0200)
- Makes the code much more obvious to follow since we're not swapping
  path/opath back and forwards just to be able to use a throwaway
  path for the rename. Dont bother null-checking on logging,
  if one of the paths was null we'd be dead already.
- Also fixes an ancient memleak: when osuffix is in use, fsm->path
  gets newly malloced before fsmVerify() but this part did another
  allocation on it, didn't save and restore fsm->path .. and nothing
  was freeing the original (local) allocation of fsm->path, only
  restoring the previous value.

lib/fsm.c

index fe3a56c..1e832cf 100644 (file)
--- a/lib/fsm.c
+++ b/lib/fsm.c
@@ -1789,19 +1789,17 @@ if (!(fsm->mapFlags & CPIO_ALL_HARDLINKS)) break;
            rc = fsmVerify(fsm);
 
            if (rc == 0 && fsm->osuffix) {
-               char * opath = fsm->opath;
-               fsm->opath = fsm->path;
-               fsm->path = fsmFsPath(fsm, st, NULL, fsm->osuffix);
-               rc = fsmRename(fsm->opath, fsm->path, fsm->mapFlags);
+               char * spath = fsmFsPath(fsm, st, NULL, fsm->osuffix);
+               rc = fsmRename(fsm->path, spath, fsm->mapFlags);
                if (!rc)
-                   rpmlog(RPMLOG_WARNING,
-                       _("%s saved as %s\n"),
-                               (fsm->opath ? fsm->opath : ""),
-                               (fsm->path ? fsm->path : ""));
-               fsm->path = _free(fsm->path);
-               fsm->opath = opath;
+                   rpmlog(RPMLOG_WARNING, _("%s saved as %s\n"),
+                          fsm->path, spath);
+               free(spath);
            }
 
+           if (fsm->osuffix)
+               free(fsm->path);
+
            fsm->path = path;
            if (!(rc == CPIOERR_ENOENT)) return rc;
            rc = expandRegular(fsm);