Handle NULL header in doHeaderUnload()
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 9 Sep 2009 09:17:10 +0000 (12:17 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 9 Sep 2009 09:17:10 +0000 (12:17 +0300)
- avoids having to separately check elsewhere and avoids segfaulting
  on headerUnload() and headerReload() on NULL headers

lib/header.c

index 45bbc2d..c4cc78e 100644 (file)
@@ -456,6 +456,8 @@ static void * doHeaderUnload(Header h,
     int i;
     int drlen, ndribbles;
 
+    if (h == NULL) return NULL;
+
     /* Sort entries by (offset,tag). */
     headerUnsort(h);
 
@@ -1013,8 +1015,6 @@ int headerWrite(FD_t fd, Header h, enum hMagic magicp)
     size_t length;
     void * uh;
 
-    if (h == NULL)
-       return 1;
     uh = doHeaderUnload(h, &length);
     if (uh == NULL)
        return 1;