libhelper: fixup memory leak

This commit is contained in:
2025-07-26 10:28:17 +03:00
parent 7017cfc9a4
commit 40260d5ae3
8 changed files with 34 additions and 17 deletions

View File

@@ -23,6 +23,15 @@
#include <stdarg.h>
#include <libhelper/lib.hpp>
static void __create_log_file(const char* file)
{
int fd = open(file, O_WRONLY | O_TRUNC, DEFAULT_EXTENDED_FILE_PERMS);
if (fd == -1) {
fd = open(file, O_WRONLY | O_CREAT, DEFAULT_EXTENDED_FILE_PERMS);
if (fd != -1) close(fd);
} else if (fd != -1) close(fd);
}
namespace Helper {
Error::Error(const char* format, ...)
@@ -56,7 +65,7 @@ Logger::~Logger()
currentTime().data(),
_oss.str().data());
if (!isExists(_logFile)) createFile(_logFile);
if (!isExists(_logFile)) __create_log_file(_logFile);
FILE* fp = fopen(_logFile, "a");
if (fp != NULL) {