svn commit: r341540 - head/contrib/ofed/libibverbs
Slava Shwartsman
slavash at FreeBSD.org
Wed Dec 5 13:28:18 UTC 2018
Author: slavash
Date: Wed Dec 5 13:28:17 2018
New Revision: 341540
URL: https://svnweb.freebsd.org/changeset/base/341540
Log:
libibverbs: Fix memory leak in ibv_read_sysfs_file().
Testing packetdrill using valgrind resulted in finding a memory leak in
ibv_read_sysfs_file(). The attached patch fixes it.
Submitted by: tuexen@
Approved by: hselasky (mentor)
MFC after: 1 week
Sponsored by: Mellanox Technologies
Modified:
head/contrib/ofed/libibverbs/sysfs.c
Modified: head/contrib/ofed/libibverbs/sysfs.c
==============================================================================
--- head/contrib/ofed/libibverbs/sysfs.c Wed Dec 5 13:27:48 2018 (r341539)
+++ head/contrib/ofed/libibverbs/sysfs.c Wed Dec 5 13:28:17 2018 (r341540)
@@ -79,7 +79,7 @@ int ibv_read_sysfs_file(const char *dir, const char *f
char *buf, size_t size)
{
char *path, *s;
- int fd;
+ int ret;
size_t len;
if (asprintf(&path, "%s/%s", dir, file) < 0)
@@ -89,11 +89,12 @@ int ibv_read_sysfs_file(const char *dir, const char *f
if (*s == '/')
*s = '.';
- len = size;
- if (sysctlbyname(&path[1], buf, &len, NULL, 0) == -1)
- return -1;
-
+ len = size;
+ ret = sysctlbyname(&path[1], buf, &len, NULL, 0);
free(path);
+
+ if (ret == -1)
+ return -1;
if (len > 0 && buf[len - 1] == '\n')
buf[--len] = '\0';
More information about the svn-src-all
mailing list