diff --git a/rdkPlugins/Logging/source/FileSink.cpp b/rdkPlugins/Logging/source/FileSink.cpp index 4beb5fe6..fdf3c850 100644 --- a/rdkPlugins/Logging/source/FileSink.cpp +++ b/rdkPlugins/Logging/source/FileSink.cpp @@ -77,7 +77,7 @@ FileSink::FileSink(const std::string &containerId, std::shared_ptr 0) + if (mDevNullFd >= 0) { mOutputFileFd = mDevNullFd; } @@ -88,17 +88,20 @@ FileSink::FileSink(const std::string &containerId, std::shared_ptr= 0 && mOutputFileFd != mDevNullFd) { - AI_LOG_SYS_ERROR(errno, "Failed to close /dev/null"); + if (close(mOutputFileFd) < 0) + { + AI_LOG_SYS_ERROR(errno, "Failed to close output file"); + } } - if (mOutputFileFd > 0) + if (mDevNullFd >= 0) { - if (close(mOutputFileFd) < 0) + if (close(mDevNullFd) < 0) { - AI_LOG_SYS_ERROR(errno, "Failed to close output file"); + AI_LOG_SYS_ERROR(errno, "Failed to close /dev/null"); } } } @@ -117,6 +120,11 @@ void FileSink::DumpLog(const int bufferFd) std::lock_guard locker(mLock); + if (mOutputFileFd < 0) { + AI_LOG_ERROR("Invalid output file descriptor"); + return; + } + ssize_t ret; ssize_t offset = 0; @@ -264,4 +272,4 @@ int FileSink::openFile(const std::string &pathName) } return openedFd; -} \ No newline at end of file +}