Make parseChangeLog() return PART_ERROR on errors
authorPanu Matilainen <pmatilai@redhat.com>
Mon, 5 May 2008 07:42:41 +0000 (10:42 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Mon, 5 May 2008 07:42:41 +0000 (10:42 +0300)
- streamline exits, fixing memleak from stringbuf on various paths

build/parseChangelog.c

index 7cf1e9a..b0dc135 100644 (file)
@@ -203,29 +203,34 @@ static rpmRC addChangelog(Header h, StringBuf sb)
 
 int parseChangelog(rpmSpec spec)
 {
-    int nextPart, res, rc;
+    int nextPart, rc, res = PART_ERROR;
     StringBuf sb = newStringBuf();
     
     /* There are no options to %changelog */
     if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
-       sb = freeStringBuf(sb);
-       return PART_NONE;
+       res = PART_NONE;
+       goto exit;
+    } else if (rc < 0) {
+       goto exit;
     }
-    if (rc)
-       return rc;
     
     while (! (nextPart = isPart(spec->line))) {
        appendStringBuf(sb, spec->line);
        if ((rc = readLine(spec, STRIP_COMMENTS)) > 0) {
            nextPart = PART_NONE;
            break;
+       } else if (rc < 0) {
+           goto exit;
        }
-       if (rc)
-           return rc;
     }
 
-    res = addChangelog(spec->packages->header, sb);
+    if (addChangelog(spec->packages->header, sb)) {
+       goto exit;
+    }
+    res = nextPart;
+
+exit:
     sb = freeStringBuf(sb);
 
-    return (res) ? res : nextPart;
+    return res;
 }