Merge pull request #1516 from tklauser/fix-cstring-leaks

mount: fix CString memory leaks
This commit is contained in:
Michael Crosby 2017-09-15 10:06:20 -04:00 committed by GitHub
commit 4bfe3a9998

View File

@ -4,17 +4,24 @@ package mount
/* /*
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <sys/mnttab.h> #include <sys/mnttab.h>
*/ */
import "C" import "C"
import ( import (
"fmt" "fmt"
"unsafe"
) )
// Self retrieves a list of mounts for the current running process. // Self retrieves a list of mounts for the current running process.
func Self() ([]Info, error) { func Self() ([]Info, error) {
mnttab := C.fopen(C.CString(C.MNTTAB), C.CString("r")) path := C.CString(C.MNTTAB)
defer C.free(unsafe.Pointer(path))
mode := C.CString("r")
defer C.free(unsafe.Pointer(mode))
mnttab := C.fopen(path, mode)
if mnttab == nil { if mnttab == nil {
return nil, fmt.Errorf("Failed to open %s", C.MNTTAB) return nil, fmt.Errorf("Failed to open %s", C.MNTTAB)
} }