mirror of
https://github.com/rancher/os.git
synced 2025-08-24 01:18:19 +00:00
Fix memory leak in selinux_linux.go
This commit is contained in:
parent
36529b5f0e
commit
ac46b4f337
@ -2,8 +2,13 @@ package selinux
|
|||||||
|
|
||||||
// #cgo pkg-config: libselinux libsepol
|
// #cgo pkg-config: libselinux libsepol
|
||||||
// #include <selinux/selinux.h>
|
// #include <selinux/selinux.h>
|
||||||
|
// #include <stdlib.h>
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
func InitializeSelinux() (int, error) {
|
func InitializeSelinux() (int, error) {
|
||||||
enforce := C.int(0)
|
enforce := C.int(0)
|
||||||
ret, err := C.selinux_init_load_policy(&enforce)
|
ret, err := C.selinux_init_load_policy(&enforce)
|
||||||
@ -11,6 +16,12 @@ func InitializeSelinux() (int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SetFileContext(path string, context string) (int, error) {
|
func SetFileContext(path string, context string) (int, error) {
|
||||||
ret, err := C.setfilecon(C.CString(path), C.CString(context))
|
cPath := C.CString(path)
|
||||||
|
defer C.free(unsafe.Pointer(cPath))
|
||||||
|
|
||||||
|
cContext := C.CString(context)
|
||||||
|
defer C.free(unsafe.Pointer(cContext))
|
||||||
|
|
||||||
|
ret, err := C.setfilecon(cPath, cContext)
|
||||||
return int(ret), err
|
return int(ret), err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user