Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Commit

Permalink
persistence: Fix resource leak
Browse files Browse the repository at this point in the history
File was not being closed upon write failure.

Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
  • Loading branch information
edersondisouza committed Sep 3, 2015
1 parent 32d13ad commit 3090e04
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/modules/flow/persistence/fs-storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ int
fs_write(const char *name, struct sol_buffer *buffer)
{
FILE *file;
int ret = 0;

file = fopen(name, "w+e");
if (!file) {
Expand All @@ -58,15 +59,15 @@ fs_write(const char *name, struct sol_buffer *buffer)
fwrite(buffer->data, buffer->used, 1, file);
if (ferror(file)) {
SOL_WRN("Could not write to persistence file [%s]", name);
return -EIO;
ret = -EIO;
}

if (fclose(file)) {
SOL_WRN("Could not close persistence file [%s]", name);
return -errno;
}

return 0;
return ret;
}

int
Expand Down

0 comments on commit 3090e04

Please sign in to comment.