From 42ab8763f08156c2d0a63f8add383f3da7161006 Mon Sep 17 00:00:00 2001 From: Samuel Coleman Date: Mon, 3 May 2021 20:39:09 +0100 Subject: [PATCH] Fix FD leak when checking lock dir permissions. `mkstemp(3)` creates and opens a file descriptor for a temporary file, but this file descriptor was immediately discarded in favour of `fopen(3)`'ing the file by name and using that `FILE *` stream. I'm sure whoever originally wrote this code meant to use `mktemp(3)` instead, which only creates a unique file from a template name (equivalent to `mktemp(1)`). --- src/main/c/src/SerialImp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/c/src/SerialImp.c b/src/main/c/src/SerialImp.c index 85833a86..4d7a8b8e 100644 --- a/src/main/c/src/SerialImp.c +++ b/src/main/c/src/SerialImp.c @@ -5835,7 +5835,7 @@ int check_group_uucp() strcat(testLockAbsFileName, testLockFileDirName); strcat(testLockAbsFileName, "/"); strcat(testLockAbsFileName, testLockFileName); - if ( 0 == mkstemp(testLockAbsFileName) ) + if ( NULL == mktemp(testLockAbsFileName) ) { free(testLockAbsFileName); report_error("check_group_uucp(): mktemp malformed string - \