Merge pull request #1516 from tklauser/fix-cstring-leaks
mount: fix CString memory leaks
This commit is contained in:
commit
4bfe3a9998
@ -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)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user