summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/csv.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/csv.c b/lib/csv.c
index 7df929264..4fd14918f 100644
--- a/lib/csv.c
+++ b/lib/csv.c
@@ -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++;