Fix memory leak in Entry::getEntry()
The getEntry() function is a D-Bus method that returns a file
descriptor. While the file descriptor was being closed after the method
return was sent so descriptors didn't leak, an fclose() was never
called which appears to leak a bit over 300 bytes according to
valgrind.
Just use open() instead, as the code doesn't actually need to read the
file contents anyway.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Icbe1cd157054f1842aa5b90535f0e3f48db6460a
diff --git a/elog_entry.cpp b/elog_entry.cpp
index 1bd70c2..85751ed 100644
--- a/elog_entry.cpp
+++ b/elog_entry.cpp
@@ -3,6 +3,7 @@
#include "elog_serialize.hpp"
#include "log_manager.hpp"
+#include <fcntl.h>
#include <unistd.h>
#include <xyz/openbmc_project/Common/File/error.hpp>
@@ -73,8 +74,8 @@
sdbusplus::message::unix_fd Entry::getEntry()
{
- FILE* fp = fopen(path().c_str(), "rb");
- if (fp == nullptr)
+ int fd = open(path().c_str(), O_RDONLY | O_NONBLOCK);
+ if (fd == -1)
{
auto e = errno;
log<level::ERR>("Failed to open Entry File", entry("ERRNO=%d", e),
@@ -82,8 +83,6 @@
throw sdbusplus::xyz::openbmc_project::Common::File::Error::Open();
}
- auto fd = fileno(fp);
-
// Schedule the fd to be closed by sdbusplus when it sends it back over
// D-Bus.
sdeventplus::Event event = sdeventplus::Event::get_default();