From: Alan T. DeKok Date: Mon, 25 Apr 2016 17:42:06 +0000 (-0400) Subject: Move common code to cleanup routine X-Git-Tag: release_3_0_12~153 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9e9af34ea0dc05f8a98e4de30d511f54f5f5d961;p=thirdparty%2Ffreeradius-server.git Move common code to cleanup routine --- diff --git a/src/main/exfile.c b/src/main/exfile.c index cb0e2eee015..61c780f43a5 100644 --- a/src/main/exfile.c +++ b/src/main/exfile.c @@ -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 @@ -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]); } } @@ -265,11 +272,7 @@ do_return: 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;