diff options
| author | Donald Sharp <sharpd@cumulusnetworks.com> | 2017-02-08 13:44:53 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-02-08 13:44:53 -0500 |
| commit | 10c7cd3920b0105a009dae138a481f56473bc463 (patch) | |
| tree | 061c082c167150c7b24d1a16021efc2abc31fcab /lib/csv.c | |
| parent | e6b737294a80af25060216cbf91b13f2c3a617b4 (diff) | |
| parent | 8ac885457f9a16032fcc157488c0b0ea48a686c1 (diff) | |
Merge pull request #185 from opensourcerouting/coverity-lib-1
Coverity foo
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++; |
