Skip to content

Commit

Permalink
Merge pull request #4 from tcullum-gpsw/fix-file-handle-leaks
Browse files Browse the repository at this point in the history
Fixed file handle leaks in read_from_file() and write_to_file()
  • Loading branch information
dnewman-gpsw committed Jun 29, 2018
2 parents 77bcd76 + e975a95 commit 7fc345e
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions source/lib/common/private/gpr_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down

0 comments on commit 7fc345e

Please sign in to comment.