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);
if (!fld) {
log_error("fld malloc failed\n");
csv_remove_record(csv, rec);
+ va_end(list);
return (NULL);
}
if (tempc < (count - 1)) {
curr = (char *)calloc(1, csv->buflen);
if (!curr) {
log_error("field str malloc failed\n");
- return (NULL);
+ goto out_rec;
}
rec->record = curr;
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);
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",
csv_insert_record(csv, rec);
return rec;
+
+out_curr:
+ free(curr);
+out_rec:
+ free(rec);
+ return NULL;
}
void
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++;