Skip to content

Commit

Permalink
Move common code to cleanup routine
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Apr 25, 2016
1 parent 5c2feb9 commit 9e9af34
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/main/exfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ exfile_t *exfile_init(TALLOC_CTX *ctx, uint32_t max_entries, uint32_t max_idle,
return ef;
}


static void exfile_cleanup_entry(exfile_entry_t *entry)
{
TALLOC_FREE(entry->filename);

close(entry->fd);
entry->hash = 0;
entry->fd = -1;
entry->dup = -1;
}

/** Open a new log file, or maybe an existing one.
*
* When multithreaded, the FD is locked via a mutex. This way we're
Expand Down Expand Up @@ -165,11 +176,7 @@ int exfile_open(exfile_t *ef, char const *filename, mode_t permissions, bool app
* This will block forever if a thread is
* doing something stupid.
*/
TALLOC_FREE(ef->entries[i].filename);
ef->entries[i].hash = 0;
close(ef->entries[i].fd);
ef->entries[i].fd = -1;
ef->entries[i].dup = -1;
exfile_cleanup_entry(&ef->entries[i]);
}
}

Expand Down Expand Up @@ -265,11 +272,7 @@ int exfile_open(exfile_t *ef, char const *filename, mode_t permissions, bool app
fr_strerror_printf("Failed to seek in file %s: %s", filename, strerror(errno));

error:
ef->entries[i].hash = 0;
TALLOC_FREE(ef->entries[i].filename);
close(ef->entries[i].fd);
ef->entries[i].fd = -1;
ef->entries[i].dup = -1;
exfile_cleanup_entry(&ef->entries[i]);

PTHREAD_MUTEX_UNLOCK(&(ef->mutex));
return -1;
Expand Down

0 comments on commit 9e9af34

Please sign in to comment.