Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Dec 2018 11:37:43 +0000 (UTC)
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r341894 - stable/12/contrib/ofed/libibverbs
Message-ID:  <201812121137.wBCBbhkJ051910@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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';



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201812121137.wBCBbhkJ051910>