Tolerate NULL in rpmfsFree() and rpmfsFC()
authorPanu Matilainen <pmatilai@redhat.com>
Thu, 6 May 2010 11:55:38 +0000 (14:55 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Thu, 6 May 2010 12:09:47 +0000 (15:09 +0300)
- both are "can't happen" situations but easy to handle cleanly here...

lib/rpmfs.c

index f5d4788..f07603a 100644 (file)
@@ -26,17 +26,20 @@ rpmfs rpmfsNew(unsigned int fc, rpmElementType type)
     return fs;
 }
 
-rpmfs rpmfsFree(rpmfs fs) {
-    fs->replaced = _free(fs->replaced);
-    fs->states = _free(fs->states);
-    fs->actions = _free(fs->actions);
-
-    fs = _free(fs);
-    return fs;
+rpmfs rpmfsFree(rpmfs fs)
+{
+    if (fs != NULL) {
+       fs->replaced = _free(fs->replaced);
+       fs->states = _free(fs->states);
+       fs->actions = _free(fs->actions);
+       fs = _free(fs);
+    }
+    return NULL;
 }
 
-rpm_count_t rpmfsFC(rpmfs fs) {
-    return fs->fc;
+rpm_count_t rpmfsFC(rpmfs fs)
+{
+    return (fs != NULL) ? fs->fc : 0;
 }
 
 void rpmfsAddReplaced(rpmfs fs, int pkgFileNum, int otherPkg, int otherFileNum)