summaryrefslogtreecommitdiff
path: root/lib/csv.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/csv.c')
-rw-r--r--lib/csv.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/lib/csv.c b/lib/csv.c
index 95e3e97768..bfe712bade 100644
--- a/lib/csv.c
+++ b/lib/csv.c
@@ -13,10 +13,9 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with Quagga; see the file COPYING. If not, write to the Free
- * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <stdlib.h>
@@ -177,11 +176,11 @@ csv_decode_record(csv_record_t *rec)
field = strpbrk(curr, ",");
}
field = strstr(curr, "\n");
- if (!field) {
+ if (!field)
return;
- }
+
fld = malloc(sizeof(csv_field_t));
- if (field && fld) {
+ if (fld) {
fld->field = curr;
fld->field_len = field-curr;
TAILQ_INSERT_TAIL(&(rec->fields), fld, next_field);
@@ -242,9 +241,8 @@ csv_encode (csv_t *csv,
rec = malloc(sizeof(csv_record_t));
if (!rec) {
log_error("record malloc failed\n");
- if (!buf) {
- free(str);
- }
+ if (!buf)
+ free(str);
va_end(list);
return (NULL);
}
@@ -262,6 +260,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)) {
@@ -423,6 +422,7 @@ csv_clone_record (csv_t *csv, csv_record_t *in_rec, csv_record_t **out_rec)
curr = calloc(1, csv->buflen);
if (!curr) {
log_error("field str malloc failed\n");
+ free(rec);
return;
}
rec->record = curr;
@@ -525,7 +525,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;
@@ -533,7 +533,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);
@@ -542,7 +542,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",
@@ -563,6 +563,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
@@ -576,6 +582,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++;