]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Close FD on error (#4848)
authorJorge Pereira <jpereira@users.noreply.github.com>
Mon, 16 Jan 2023 22:08:56 +0000 (19:08 -0300)
committerGitHub <noreply@github.com>
Mon, 16 Jan 2023 22:08:56 +0000 (16:08 -0600)
* Close FD on error

* Fix indent

Co-authored-by: Arran Cudbard-Bell <a.cudbardb@freeradius.org>
src/modules/rlm_linelog/rlm_linelog.c

index af1359452876eb6fa1e1031cd2148f7b67884b4e..8f381fc7ca293b8af361de79ddb8a4e3591d0838 100644 (file)
@@ -281,23 +281,20 @@ static rlm_rcode_t CC_HINT(nonnull) mod_do_linelog(void *instance, REQUEST *requ
        if (inst->header && (offset == 0)) {
                char header[4096];
                if (radius_xlat(header, sizeof(header) - 1, request, inst->header, linelog_escape_func, NULL) < 0) {
+               error:
+                       exfile_close(inst->ef, fd);
                        return RLM_MODULE_FAIL;
                }
                strcat(header, "\n");
                if (write(fd, header, strlen(header)) < 0) {
-                       exfile_close(inst->ef, fd);
                        ERROR("rlm_linelog: Failed writing: %s", fr_syserror(errno));
-                       return RLM_MODULE_FAIL;
+                       goto error;
                }
        }
 
        strcat(line, "\n");
 
-       if (write(fd, line, strlen(line)) < 0) {
-               exfile_close(inst->ef, fd);
-               ERROR("rlm_linelog: Failed writing: %s", fr_syserror(errno));
-               return RLM_MODULE_FAIL;
-       }
+       if (write(fd, line, strlen(line)) < 0) goto error;
 
        exfile_close(inst->ef, fd);
        return RLM_MODULE_OK;