Fixed file handle leaks in read_from_file() and write_to_file() in cases where we performed an error (-1) return

pull/4/head
Todd Cullum 2018-05-25 16:25:43 -07:00
rodzic af95987d44
commit e975a95239
1 zmienionych plików z 3 dodań i 0 usunięć

Wyświetl plik

@ -42,6 +42,7 @@ int read_from_file(gpr_buffer* buffer, const char* file_path, gpr_malloc malloc_
if ( buffer->buffer == NULL)
{
fputs ("Memory error", stderr);
fclose(fIN);
return -1;
}
@ -50,6 +51,7 @@ int read_from_file(gpr_buffer* buffer, const char* file_path, gpr_malloc malloc_
{
free_function(buffer->buffer);
fputs ("Reading error", stderr);
fclose(fIN);
return -1;
}
@ -73,6 +75,7 @@ int write_to_file(const gpr_buffer* buffer, const char* file_path)
if( bytes_written != buffer->size ) {
fputs("Could not write bytes \n", stderr);
perror("fwrite()");
fclose(fOUT);
return -2;
}