Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed file handle leaks in read_from_file() and write_to_file() #4

Merged
merged 1 commit into from
Jun 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fixed file handle leaks in read_from_file() and write_to_file() in ca…
…ses where we performed an error (-1) return
  • Loading branch information
tcullum-gpsw committed May 25, 2018
commit e975a95239e934fbd08df8faa4d63720f149e6d8
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