diff options
author | David Lamparter <equinox@opensourcerouting.org> | 2017-02-08 15:28:01 +0100 |
---|---|---|
committer | David Lamparter <equinox@opensourcerouting.org> | 2017-02-08 16:35:02 +0100 |
commit | 8ac885457f9a16032fcc157488c0b0ea48a686c1 (patch) | |
tree | ac7141d49b66bfac8ca7785f2374fd62b47235d9 /lib/csv.c | |
parent | lib: fix some coverity NULL check warnings (diff) | |
download | frr-8ac885457f9a16032fcc157488c0b0ea48a686c1.tar.xz frr-8ac885457f9a16032fcc157488c0b0ea48a686c1.zip |
lib: csv: plug memleaks
Reported-by: Coverity Scan
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'lib/csv.c')
-rw-r--r-- | lib/csv.c | 18 |
1 files changed, 15 insertions, 3 deletions
@@ -239,6 +239,9 @@ csv_encode (csv_t *csv, rec = malloc(sizeof(csv_record_t)); if (!rec) { log_error("record malloc failed\n"); + if (!buf) + free(str); + va_end(list); return (NULL); } csv_init_record(rec); @@ -255,6 +258,7 @@ csv_encode (csv_t *csv, if (!fld) { log_error("fld malloc failed\n"); csv_remove_record(csv, rec); + va_end(list); return (NULL); } if (tempc < (count - 1)) { @@ -518,7 +522,7 @@ csv_concat_record (csv_t *csv, curr = (char *)calloc(1, csv->buflen); if (!curr) { log_error("field str malloc failed\n"); - return (NULL); + goto out_rec; } rec->record = curr; @@ -526,7 +530,7 @@ csv_concat_record (csv_t *csv, ret = strstr(rec1->record, "\n"); if (!ret) { log_error("rec1 str not properly formatted\n"); - return (NULL); + goto out_curr; } snprintf(curr, (int)(ret - rec1->record + 1), "%s", rec1->record); @@ -535,7 +539,7 @@ csv_concat_record (csv_t *csv, ret = strstr(rec2->record, "\n"); if (!ret) { log_error("rec2 str not properly formatted\n"); - return (NULL); + goto out_curr; } snprintf((curr+strlen(curr)), (int)(ret - rec2->record + 1), "%s", @@ -556,6 +560,12 @@ csv_concat_record (csv_t *csv, csv_insert_record(csv, rec); return rec; + +out_curr: + free(curr); +out_rec: + free(rec); + return NULL; } void @@ -569,6 +579,8 @@ csv_decode (csv_t *csv, char *inbuf) pos = strpbrk(buf, "\n"); while (pos != NULL) { rec = calloc(1, sizeof(csv_record_t)); + if (!rec) + return; csv_init_record(rec); TAILQ_INSERT_TAIL(&(csv->records), rec, next_record); csv->num_recs++; |