]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: csv: plug memleaks 185/head
authorDavid Lamparter <equinox@opensourcerouting.org>
Wed, 8 Feb 2017 14:28:01 +0000 (15:28 +0100)
committerDavid Lamparter <equinox@opensourcerouting.org>
Wed, 8 Feb 2017 15:35:02 +0000 (16:35 +0100)
Reported-by: Coverity Scan
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
lib/csv.c

index 7df9292647bf9408af76bc2e898a85c47d4cf8d6..4fd14918fd689e84e68850a2f908f91cebbc685e 100644 (file)
--- 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++;