From 86c5b9a80d284779be8e752b2f84fec69f59f7e7 Mon Sep 17 00:00:00 2001 From: gfyoung Date: Sun, 11 Jun 2017 16:58:30 -0700 Subject: [PATCH] MAINT: Buttress memory handling in C csv engine Follow-up to gh-16663. --- pandas/_libs/src/parser/io.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pandas/_libs/src/parser/io.c b/pandas/_libs/src/parser/io.c index 4381ef19e991b..a82552c960074 100644 --- a/pandas/_libs/src/parser/io.c +++ b/pandas/_libs/src/parser/io.c @@ -15,6 +15,10 @@ The full license is in the LICENSE file, distributed with this software. void *new_file_source(char *fname, size_t buffer_size) { file_source *fs = (file_source *)malloc(sizeof(file_source)); + if (fs == NULL) { + return NULL; + } + fs->fp = fopen(fname, "rb"); if (fs->fp == NULL) { @@ -29,6 +33,9 @@ void *new_file_source(char *fname, size_t buffer_size) { fs->buffer = (char *)malloc((buffer_size + 1) * sizeof(char)); if (fs->buffer == NULL) { + fclose(fs->fp); + free(fs); + return NULL; } @@ -187,7 +194,8 @@ void *new_mmap(char *fname) { /* XXX Eventually remove this print statement. */ fprintf(stderr, "new_file_buffer: mmap() failed.\n"); free(mm); - mm = NULL; + + return NULL; } return (void *)mm;