[PATCH skeleton v4 07/13] fix info memory leak
Vishwanatha Subbanna
vishwanath at in.ibm.com
Wed Mar 23 18:15:07 AEDT 2016
hello,
I wonder if you wanted to say "Fix resource leak" as I don't see any memory
leak getting fixed here. Am I missing anything ?
Also, a close(fd) on open failure may lead to unexpected behavior since the
file is not even opened.
Also, the pattern seems to be multiple error paths with same set of
instructions. Does it make sense to put them in a macro -or- better yet
have fd auto cleaned using the cleanup attribute ?
https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
Thanks
-------------------------------------------------------------------------------------
Thanks and Regards,
Vishwanath.
Advisory Software Engineer,
Power Firmware Development,
Systems &Technology Lab,
MG2-6F-255 , Manyata Embassy Business Park,
Bangalore , KA , 560045
Ph: +91-80-46678255
E-mail: vishwanath at in.ibm.com
----------------------------------------------------------------------------------
From: OpenBMC Patches <openbmc-patches at stwcx.xyz>
To: openbmc at lists.ozlabs.org
Cc: Ken <ken1029 at gmail.com>
Date: 23/03/2016 11:25 am
Subject: [PATCH skeleton v4 07/13] fix info memory leak
Sent by: "openbmc" <openbmc-bounces
+vishwanath=in.ibm.com at lists.ozlabs.org>
From: Ken <ken1029 at gmail.com>
---
objects/info.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/objects/info.c b/objects/info.c
index ab2d98c..d872c3f 100644
--- a/objects/info.c
+++ b/objects/info.c
@@ -42,6 +42,7 @@ static int i2c_open() {
fd = open(fn, O_RDWR);
if (fd == -1) {
LOG_ERR(errno, "Failed to open i2c device %s", fn);
+ close(fd);
return -1;
}
@@ -108,6 +109,7 @@ static int i2c_io(int fd) {
rc = ioctl(fd, I2C_RDWR, &data);
if (rc < 0) {
LOG_ERR(errno, "Failed to do raw io");
+ close(fd);
return -1;
}
@@ -126,6 +128,7 @@ int get_hdd_status(void)
}
if (i2c_io(fd) < 0) {
+ close(fd);
return -1;
}
@@ -145,7 +148,7 @@ int get_hdd_status(void)
g_read_tmp[2]=g_read_bytes[2];
g_read_tmp[3]=g_read_bytes[3];
-
+ close(fd);
}
int send_esel_to_dbus(const char *desc, const char *sev, const char
*details, uint8_t *debug, size_t debuglen) {
--
2.7.1
_______________________________________________
openbmc mailing list
openbmc at lists.ozlabs.org
https://lists.ozlabs.org/listinfo/openbmc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ozlabs.org/pipermail/openbmc/attachments/20160323/50b3e0c7/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: graycol.gif
Type: image/gif
Size: 105 bytes
Desc: not available
URL: <http://lists.ozlabs.org/pipermail/openbmc/attachments/20160323/50b3e0c7/attachment-0001.gif>
More information about the openbmc
mailing list