[lxc-devel] [lxd/master] shared: Fix growing of buf in GroupId
stgraber on Github
lxc-bot at linuxcontainers.org
Thu Aug 24 19:41:48 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170824/a4766f89/attachment.bin>
-------------- next part --------------
From 0c138f1f5a6f676b400ac41d091795543770cf67 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Thu, 24 Aug 2017 15:40:58 -0400
Subject: [PATCH] shared: Fix growing of buf in GroupId
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Closes #3711
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
shared/util_linux.go | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/shared/util_linux.go b/shared/util_linux.go
index 02f380822..33747f191 100644
--- a/shared/util_linux.go
+++ b/shared/util_linux.go
@@ -411,7 +411,6 @@ func GroupId(name string) (int, error) {
if buf == nil {
return -1, fmt.Errorf("allocation failed")
}
- defer C.free(buf)
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
@@ -422,7 +421,7 @@ again:
(*C.char)(buf),
bufSize,
&result)
- if rv < 0 {
+ if rv != 0 {
// OOM killer will take care of us if we end up doing this too
// often.
if errno == syscall.ERANGE {
@@ -434,8 +433,11 @@ again:
buf = tmp
goto again
}
+
+ C.free(buf)
return -1, fmt.Errorf("failed group lookup: %s", syscall.Errno(rv))
}
+ C.free(buf)
if result == nil {
return -1, fmt.Errorf("unknown group %s", name)
More information about the lxc-devel
mailing list