Skip to content

Commit fe0c53e

Browse files
committed
MAINT: Buttress memory handling in C csv engine
Follow-up to pandas-devgh-16663.
1 parent 0281886 commit fe0c53e

File tree

1 file changed

+9
-1
lines changed
  • pandas/_libs/src/parser

1 file changed

+9
-1
lines changed

pandas/_libs/src/parser/io.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ The full license is in the LICENSE file, distributed with this software.
1515

1616
void *new_file_source(char *fname, size_t buffer_size) {
1717
file_source *fs = (file_source *)malloc(sizeof(file_source));
18+
if (fs == NULL) {
19+
return NULL;
20+
}
21+
1822
fs->fp = fopen(fname, "rb");
1923

2024
if (fs->fp == NULL) {
@@ -29,6 +33,9 @@ void *new_file_source(char *fname, size_t buffer_size) {
2933
fs->buffer = (char *)malloc((buffer_size + 1) * sizeof(char));
3034

3135
if (fs->buffer == NULL) {
36+
fclose(fs->fp);
37+
free(fs);
38+
3239
return NULL;
3340
}
3441

@@ -187,7 +194,8 @@ void *new_mmap(char *fname) {
187194
/* XXX Eventually remove this print statement. */
188195
fprintf(stderr, "new_file_buffer: mmap() failed.\n");
189196
free(mm);
190-
mm = NULL;
197+
198+
return NULL;
191199
}
192200

193201
return (void *)mm;

0 commit comments

Comments
 (0)