]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: fix mem-leaks in samples
authorKarel Zak <kzak@redhat.com>
Thu, 23 Nov 2017 14:24:59 +0000 (15:24 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 23 Nov 2017 14:24:59 +0000 (15:24 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/samples/fromfile.c
libsmartcols/samples/title.c

index de0a8eac4a4479eec16e663d9bcd973056edd679..c1ab728fd65f419302adc05f77fbec9f5e42b392 100644 (file)
@@ -121,8 +121,10 @@ static struct libscols_column *parse_column(FILE *f)
                nlines++;
        }
 
+       free(line);
        return cl;
 fail:
+       free(line);
        scols_unref_column(cl);
        return NULL;
 }
@@ -152,6 +154,7 @@ static int parse_column_data(FILE *f, struct libscols_table *tb, int col)
                scols_line_set_data(ln, col, str);
        }
 
+       free(str);
        return 0;
 
 }
@@ -313,6 +316,8 @@ int main(int argc, char *argv[])
 
                if (!ln || scols_table_add_line(tb, ln))
                        err(EXIT_FAILURE, "failed to add a new line");
+
+               scols_unref_line(ln);
        }
 
        n = 0;
index 2d33b563a6dc6bda611dd6a32b80b51d9daff2fe..c25b32070658051576e6d849ff25326310d92a32 100644 (file)
@@ -103,6 +103,7 @@ int main(int argc, char *argv[])
        if (!sy)
                err_oom();
        scols_table_set_symbols(tb, sy);
+       scols_unref_symbols(sy);
 
        scols_symbols_set_title_padding(sy, "=");
        scols_cell_set_data(title, "This is center title (with padding)");