svn commit: r341894 - stable/12/contrib/ofed/libibverbs

Hans Petter Selasky hselasky at FreeBSD.org
Wed Dec 12 11:37:44 UTC 2018


Author: hselasky
Date: Wed Dec 12 11:37:43 2018
New Revision: 341894
URL: https://svnweb.freebsd.org/changeset/base/341894

Log:
  MFC r341540:
  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@
  Sponsored by:   Mellanox Technologies

Modified:
  stable/12/contrib/ofed/libibverbs/sysfs.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/contrib/ofed/libibverbs/sysfs.c
==============================================================================
--- stable/12/contrib/ofed/libibverbs/sysfs.c	Wed Dec 12 11:36:03 2018	(r341893)
+++ stable/12/contrib/ofed/libibverbs/sysfs.c	Wed Dec 12 11:37:43 2018	(r341894)
@@ -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-stable mailing list