Don't leak the source string

This commit is contained in:
Brandon Dyck 2022-11-24 22:19:40 -07:00
parent 9fbb3ab637
commit eb0121bff7

8
ph7.go
View File

@ -1,6 +1,7 @@
package ph7
/*
#include <stdlib.h>
#include "ph7.h"
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 (
"fmt"
"io"
)
type ResultCode int
@ -97,6 +99,7 @@ func (e Engine) ErrLog() (string, error) {
func (e Engine) Compile(source []byte, phpOnly bool) (*VM, error) {
csource := C.CBytes(source)
defer C.free(csource)
vm := new(VM)
var flags C.int
if phpOnly {
@ -107,7 +110,6 @@ func (e Engine) Compile(source []byte, phpOnly bool) (*VM, error) {
return nil, err
}
// TODO free csource
return vm, nil
}
@ -119,6 +121,10 @@ type VM struct {
ptr *C.ph7_vm
}
func (vm VM) SetOutputWriter(w io.Writer) error {
return nil
}
func (vm VM) ExtractOutput() (string, error) {
var s *C.char
var n C.int