【发布时间】:2021-11-23 11:50:34
【问题描述】:
每当我在 pycharm 中运行共享库时,我都会不断收到此错误:
Python(20566,0x116d67dc0) malloc: *** error for object 0x5b6222f0: pointer being freed was not allocated
Python(20566,0x116d67dc0) malloc: *** set a breakpoint in malloc_error_break to debug
Abort trap: 6
这是我的 go 代码变成了一个共享库:
package main
// #include <stdio.h>
// #include <stdlib.h>
// #include <errno.h>
import "C"
//export FreeCString
func FreeCString(ptr *C.char) {
C.free(unsafe.Pointer(ptr))
}
//export TestString
func TestString() *C.char {
return C.CString("Hello World")
}
这是我的 py 代码:
from ctypes import *
from ctypes import cdll
lib = cdll.LoadLibrary('./test.so')
b = lib.TestString()
lib.FreeCString(b)
print(b)
这里发生了什么?
【问题讨论】:
标签: python-3.x go cgo