]> sigrok.org Git - libsigrok.git/commitdiff
input/csv: Eliminate remaining memory leaks in error paths
authorGerhard Sittig <redacted>
Fri, 9 Jun 2017 21:10:40 +0000 (23:10 +0200)
committerGerhard Sittig <redacted>
Fri, 9 Jun 2017 21:21:03 +0000 (23:21 +0200)
When the processing of columns of text lines detected errors, the loop
was aborted and the routine was left, but allocated resources were not
freed. Fix the remaining memory leaks in the error code paths.

src/input/csv.c

index ad18e32293cde662cedbc55994dc84ce5350b9ae..000599a8d305bf9140fa78679aefb1b5cad72174 100644 (file)
@@ -784,6 +784,7 @@ static int process_buffer(struct sr_input *in, gboolean is_eof)
                columns = parse_line(line, inc, max_columns);
                if (!columns) {
                        sr_err("Error while parsing line %zu.", inc->line_number);
                columns = parse_line(line, inc, max_columns);
                if (!columns) {
                        sr_err("Error while parsing line %zu.", inc->line_number);
+                       g_strfreev(lines);
                        return SR_ERR;
                }
                num_columns = g_strv_length(columns);
                        return SR_ERR;
                }
                num_columns = g_strv_length(columns);
@@ -791,6 +792,7 @@ static int process_buffer(struct sr_input *in, gboolean is_eof)
                        sr_err("Column %u in line %zu is out of bounds.",
                                inc->first_column, inc->line_number);
                        g_strfreev(columns);
                        sr_err("Column %u in line %zu is out of bounds.",
                                inc->first_column, inc->line_number);
                        g_strfreev(columns);
+                       g_strfreev(lines);
                        return SR_ERR;
                }
                /*
                        return SR_ERR;
                }
                /*
@@ -801,6 +803,7 @@ static int process_buffer(struct sr_input *in, gboolean is_eof)
                        sr_err("Not enough columns for desired number of channels in line %zu.",
                                inc->line_number);
                        g_strfreev(columns);
                        sr_err("Not enough columns for desired number of channels in line %zu.",
                                inc->line_number);
                        g_strfreev(columns);
+                       g_strfreev(lines);
                        return SR_ERR;
                }
 
                        return SR_ERR;
                }
 
@@ -810,6 +813,7 @@ static int process_buffer(struct sr_input *in, gboolean is_eof)
                        ret = parse_single_column(columns[0], inc);
                if (ret != SR_OK) {
                        g_strfreev(columns);
                        ret = parse_single_column(columns[0], inc);
                if (ret != SR_OK) {
                        g_strfreev(columns);
+                       g_strfreev(lines);
                        return SR_ERR;
                }
 
                        return SR_ERR;
                }
 
@@ -818,6 +822,7 @@ static int process_buffer(struct sr_input *in, gboolean is_eof)
                if (ret != SR_OK) {
                        sr_err("Sending samples failed.");
                        g_strfreev(columns);
                if (ret != SR_OK) {
                        sr_err("Sending samples failed.");
                        g_strfreev(columns);
+                       g_strfreev(lines);
                        return SR_ERR;
                }
 
                        return SR_ERR;
                }