Don't leak the source string
This commit is contained in:
parent
9fbb3ab637
commit
eb0121bff7
8
ph7.go
8
ph7.go
@ -1,6 +1,7 @@
|
|||||||
package ph7
|
package ph7
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
#include <stdlib.h>
|
||||||
#include "ph7.h"
|
#include "ph7.h"
|
||||||
|
|
||||||
int engine_config_err_log(ph7 *pEngine, const char **pzPtr, int *pLen) {
|
int engine_config_err_log(ph7 *pEngine, const char **pzPtr, int *pLen) {
|
||||||
@ -14,6 +15,7 @@ int vm_extract_output(ph7_vm *pVm, const char **pzPtr, int *pLen) {
|
|||||||
import "C"
|
import "C"
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ResultCode int
|
type ResultCode int
|
||||||
@ -97,6 +99,7 @@ func (e Engine) ErrLog() (string, error) {
|
|||||||
|
|
||||||
func (e Engine) Compile(source []byte, phpOnly bool) (*VM, error) {
|
func (e Engine) Compile(source []byte, phpOnly bool) (*VM, error) {
|
||||||
csource := C.CBytes(source)
|
csource := C.CBytes(source)
|
||||||
|
defer C.free(csource)
|
||||||
vm := new(VM)
|
vm := new(VM)
|
||||||
var flags C.int
|
var flags C.int
|
||||||
if phpOnly {
|
if phpOnly {
|
||||||
@ -107,7 +110,6 @@ func (e Engine) Compile(source []byte, phpOnly bool) (*VM, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO free csource
|
|
||||||
return vm, nil
|
return vm, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,6 +121,10 @@ type VM struct {
|
|||||||
ptr *C.ph7_vm
|
ptr *C.ph7_vm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (vm VM) SetOutputWriter(w io.Writer) error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (vm VM) ExtractOutput() (string, error) {
|
func (vm VM) ExtractOutput() (string, error) {
|
||||||
var s *C.char
|
var s *C.char
|
||||||
var n C.int
|
var n C.int
|
||||||
|
Loading…
Reference in New Issue
Block a user