Commit 17c876aa authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

Fix open file descriptor leaks

parent e49c5012
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -184,7 +184,7 @@ static int
send_request(norns_rpc_type_t type, norns_response_t* resp, ...) {

    int res;
    int conn; 
    int conn = -1;
    bool control_request = false;
    msgbuffer_t req_buf = MSGBUFFER_INIT();
    msgbuffer_t resp_buf = MSGBUFFER_INIT();
@@ -321,6 +321,11 @@ send_request(norns_rpc_type_t type, norns_response_t* resp, ...) {

cleanup_on_error:
    va_end(ap);

    if(conn != -1) {
        close(conn);
    }

    return res;
}

+4 −0
Original line number Diff line number Diff line
@@ -120,6 +120,10 @@ log_error_helper(const char* file, int line, const char* func,
    fprintf(outfp, "%s", buffer);

end:
    if(outfp != stderr) {
        fclose(outfp);
    }

	errno = saved_errno;
}

+2 −2
Original line number Diff line number Diff line
@@ -84,8 +84,7 @@ pid_t urd::daemonize() {

    /* Fork off the parent process */
    if((pid = fork()) < 0) {
        LOGGER_ERROR("[daemonize] fork failed.");
        perror("Fork");
        LOGGER_ERROR("Failed to create child process: {}", strerror(errno));
        exit(EXIT_FAILURE);
    }

@@ -170,6 +169,7 @@ pid_t urd::daemonize() {
    }

    close(lfp);
    close(fd);

    /* Manage signals */
    signal(SIGCHLD, SIG_IGN); /* ignore child */