[openib-general] [PATCH] management: resource leak fixes
Michael S. Tsirkin
mst at mellanox.co.il
Thu May 19 06:24:16 PDT 2005
Management libraries leak resources (memory, file/directory handles).
Also a trailing whitespace fix in one place in libibcommon.
Signed-off-by: Michael S. Tsirkin <mst at mellanox.co.il>
Index: libibumad/src/umad.c
===================================================================
--- libibumad/src/umad.c (revision 2411)
+++ libibumad/src/umad.c (working copy)
@@ -357,8 +357,10 @@ get_ca(char *ca_name, umad_ca_t *ca)
if (!(dir = opendir(dir_name)))
return -ENOENT;
- if ((r = scandir(dir_name, &namelist, 0, alphasort)) < 0)
- return -EIO;
+ if ((r = scandir(dir_name, &namelist, 0, alphasort)) < 0) {
+ ret = errno < 0 ? errno : -EIO;
+ goto error;
+ }
ret = 0;
ca->numports = 0;
@@ -388,6 +390,7 @@ get_ca(char *ca_name, umad_ca_t *ca)
free(namelist[i]);
free(namelist);
+ closedir(dir);
put_ca(ca);
return 0;
@@ -395,7 +398,8 @@ clean:
for (i = 0; i < r; i++)
free(namelist[i]);
free(namelist);
-
+error:
+ closedir(dir);
release_ca(ca);
return ret;
Index: libibcommon/src/sysfs.c
===================================================================
--- libibcommon/src/sysfs.c (revision 2411)
+++ libibcommon/src/sysfs.c (working copy)
@@ -56,6 +56,7 @@
#include <sys/poll.h>
#include <syslog.h>
#include <netinet/in.h>
+#include <errno.h>
#include "common.h"
@@ -86,14 +87,20 @@ sys_read_string(char *dir_name, char *fi
if ((fd = open(path, O_RDONLY)) < 0)
return ret_code();
- if ((r = read(fd, str, max_len)) < 0)
+ if ((r = read(fd, str, max_len)) < 0) {
+ int e = errno;
+ close(fd);
+ errno = e;
return ret_code();
+ }
str[(r < max_len) ? r : max_len - 1] = 0;
if ((s = strrchr(str, '\n')))
*s = 0;
- return 0;
+
+ close(fd);
+ return 0;
}
int
--
MST - Michael S. Tsirkin
More information about the general
mailing list