Fix a leak found when using --force-reinstall.
[oweals/opkg-lede.git] / libopkg / pkg_parse.c
index 246705e8f2549ae2d2270489dcd7ff880ccaee31..d01dff51dcd192d95dc5def0ca5c4aa32599279b 100644 (file)
@@ -152,6 +152,7 @@ pkg_parse_line(pkg_t *pkg, const char *line, uint mask)
 {
        /* these flags are a bit hackish... */
        static int reading_conffiles = 0, reading_description = 0;
+       int ret = 0;
 
        switch (*line) {
        case 'A':
@@ -279,12 +280,14 @@ pkg_parse_line(pkg_t *pkg, const char *line, uint mask)
                        parse_conffiles(pkg, line);
                        goto dont_reset_flags;
                }
-               break;
 
+               /* FALLTHROUGH */
        default:
                /* For package lists, signifies end of package. */
-               if(line_is_blank(line))
-                       return 1;
+               if(line_is_blank(line)) {
+                       ret = 1;
+                       break;
+               }
        }
 
        reading_description = 0;
@@ -292,7 +295,7 @@ pkg_parse_line(pkg_t *pkg, const char *line, uint mask)
 
 dont_reset_flags:
 
-       return 0;
+       return ret;
 }
 
 int
@@ -316,7 +319,7 @@ pkg_parse_from_stream_nomalloc(pkg_t *pkg, FILE *fp, uint mask,
                                fprintf(stderr, "%s: fgets: %s\n",
                                        __FUNCTION__, strerror(errno));
                                ret = -1;
-                       } else if (strlen(*buf0) == buflen-1) {
+                       } else if (strlen(*buf0) == buf0len-1) {
                                fprintf(stderr, "%s: missing new line character"
                                                " at end of file!\n",
                                        __FUNCTION__);