代码拉取完成,页面将自动刷新
package main
/*
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
void output(char *str) {
sleep(10000);
printf("%s\n", str);
}
*/
import "C"
import (
"fmt"
"net/http"
"time"
"unsafe"
"gitee.com/menciis/gkit/watching"
_ "net/http/pprof"
)
func init() {
go func() {
w := watching.NewWatching(
watching.WithCollectInterval("2s"),
watching.WithCoolDown("5s"),
watching.WithDumpPath("/tmp"),
watching.WithTextDump(),
watching.WithThreadDump(10, 25, 100),
)
w.EnableThreadDump().Start()
time.Sleep(time.Hour)
}()
}
func leak(wr http.ResponseWriter, req *http.Request) {
go func() {
for i := 0; i < 1000; i++ {
go func() {
str := "hello cgo"
// change to char*
cstr := C.CString(str)
C.output(cstr)
C.free(unsafe.Pointer(cstr))
}()
}
}()
}
func main() {
http.HandleFunc("/leak", leak)
err := http.ListenAndServe(":10003", nil)
if err != nil {
fmt.Println(err)
return
}
select {}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。