mirror of
https://github.com/freebsd/freebsd-src
synced 2024-09-06 17:18:32 +00:00
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
This commit is contained in:
parent
3006180863
commit
a6578a04e4
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=341540
|
@ -79,7 +79,7 @@ int ibv_read_sysfs_file(const char *dir, const char *file,
|
|||
char *buf, size_t size)
|
||||
{
|
||||
char *path, *s;
|
||||
int fd;
|
||||
int ret;
|
||||
size_t len;
|
||||
|
||||
if (asprintf(&path, "%s/%s", dir, file) < 0)
|
||||
|
@ -90,11 +90,12 @@ int ibv_read_sysfs_file(const char *dir, const char *file,
|
|||
*s = '.';
|
||||
|
||||
len = size;
|
||||
if (sysctlbyname(&path[1], buf, &len, NULL, 0) == -1)
|
||||
return -1;
|
||||
|
||||
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';
|
||||
|
||||
|
|
Loading…
Reference in a new issue