返回

打扰大佬,请教一个技术问题:我用netpack和socketdriver从socket中读取到一段数据,然后我有一个处理函数 socketMsg.data(fd, msg, sz) 来处理读出的数据,此时msg是userdata,sz是数据大小;然后我在处理过程中调用netpack.tostring(msg, sz)将原始数据打包为字符串;如果在处理函数中多次调用netpack.tostring(msg, sz),发现内存会被踩坏,定为到netpack.c文件中,是ltostring(lua_State *L)中的lua_pushlstring(L, (const char *)ptr, size);这一句一直往里面崩溃了,以下是gdb信息:#0 sweepgen (L=L@entry=0x7f847b2421a8, p=0x7f847a03fe00, p@entry=0x7f8477220140, limit=0x7f847650f9d0, pfirstold1=pfirstold1@entry=0x7f84772201a8, g=<optimized out>) at lgc.c:1106#1 0x000000000042929c in youngcollection (g=0x7f84772200d0, L=0x7f847b2421a8) at lgc.c:1244#2 genstep (g=0x7f84772200d0, L=0x7f847b2421a8) at lgc.c:1439#3 luaC_step (L=L@entry=0x7f847b2421a8) at lgc.c:1689#4 0x0000000000421ec7 in lua_pushlstring (L=0x7f847b2421a8, s=<optimized out>, len=<optimized out>) at lapi.c:526#5 0x00007f8476dfdd63 in ltostring (L=0x7f847b2421a8) at lualib-src/lua-websocketnetpack.c:810#6 0x0000000000425833 in luaD_precall (L=L@entry=0x7f847b2421a8, func=func@entry=0x7f847b2c9eb0, nresults=-1) at ldo.c:532#7 0x0000000000432646 in luaV_execute (L=L@entry=0x7f847b2421a8, ci=<optimized out>, ci@entry=0x7f847580d7c0) at lvm.c:1626#8 0x00000000004254f3 in unroll (L=0x7f847b2421a8, ud=<optimized out>) at ldo.c:685#9 0x0000000000424c6a in luaD_rawrunprotected (L=L@entry=0x7f847b2421a8, f=f@entry=0x4259e0 <resume>, ud=ud@entry=0x7f847eff2c7c) at ldo.c:144#10 0x0000000000425b24 in lua_resume (L=0x7f847b2421a8, from=<optimized out>, nargs=<optimized out>, nresults=0x7f847eff2d28) at ldo.c:788#11 0x00007f84807f9b57 in lua_resumeX (L=0x7f847b2421a8, from=0x7f8477220008, nargs=7, nresults=0x7f847eff2d28) at service-src/service_snlua.c:90#12 0x00007f84807f9cb5 in auxresume (L=0x7f8477220008, co=0x7f847b2421a8, narg=7) at service-src/service_snlua.c:146#13 0x00007f84807f9eee in timing_resume (L=0x7f8477220008, co_index=1, n=7) at service-src/service_snlua.c:198#14 0x00007f84807f9fc0 in luaB_coresume (L=0x7f8477220008) at service-src/service_snlua.c:217#15 0x0000000000425833 in luaD_precall (L=L@entry=0x7f8477220008, func=func@entry=0x7f8477281230, nresults=nresults@entry=-1) at ldo.c:532#16 0x000000000043234b in luaV_execute (L=L@entry=0x7f8477220008, ci=<optimized out>) at lvm.c:1656#17 0x00000000004259b0 in ccall (L=0x7f8477220008, func=<optimized out>, nResults=<optimized out>, inc=65537) at ldo.c:577#18 0x0000000000424c6a in luaD_rawrunprotected (L=L@entry=0x7f8477220008, f=f@entry=0x421440 <f_call>, ud=ud@entry=0x7f847eff3050) at ldo.c:144#19 0x0000000000425d2e in luaD_pcall (L=L@entry=0x7f8477220008, func=func@entry=0x421440 <f_call>, u=u@entry=0x7f847eff3050, old_top=192, ef=<optimized out>) at ldo.c:892#20 0x0000000000422a97 in lua_pcallk (L=L@entry=0x7f8477220008, nargs=<optimized out>, nresults=nresults@entry=-1, errfunc=errfunc@entry=0, ctx=ctx@entry=0, k=k@entry=0x43b090 <finishpcall>) at lapi.c:1059#21 0x000000000043b1b0 in luaB_pcall (L=0x7f8477220008) at lbaselib.c:456#22 0x0000000000425833 in luaD_precall (L=L@entry=0x7f8477220008, func=func@entry=0x7f84772810a0, nresults=2) at ldo.c:532#23 0x0000000000432646 in luaV_execute (L=L@entry=0x7f8477220008, ci=<optimized out>) at lvm.c:1626#24 0x00000000004259b0 in ccall (L=0x7f8477220008, func=<optimized out>, nResults=<optimized out>, inc=65537) at ldo.c:577#25 0x0000000000424c6a in luaD_rawrunprotected (L=L@entry=0x7f8477220008, f=f@entry=0x421440 <f_call>, ud=ud@entry=0x7f847eff3320) at ldo.c:144#26 0x0000000000425d2e in luaD_pcall (L=L@entry=0x7f8477220008, func=func@entry=0x421440 <f_call>, u=u@entry=0x7f847eff3320, old_top=48, ef=<optimized out>) at ldo.c:892#27 0x0000000000422a97 in lua_pcallk (L=0x7f8477220008, nargs=<optimized out>, nresults=0, errfunc=<optimized out>, ctx=<optimized out>, k=<optimized out>) at lapi.c:1059#28 0x00007f847a5dfe57 in _cb (context=0x7f847722d000, ud=0x7f8477220008, type=6, session=0, source=0, msg=0x7f847a04e340, sz=24) at lualib-src/lua-skynet.c:75#29 0x0000000000416caa in dispatch_message (ctx=0x7f847722d000, msg=0x7f847eff3440) at skynet-src/skynet_server.c:276#30 0x0000000000416ed1 in skynet_context_message_dispatch (sm=0x7f8482008140, q=0x7f8477208c00, weight=-1) at skynet-src/skynet_server.c:336#31 0x00000000004186dc in thread_worker (p=0x7ffd5f215bd0) at skynet-src/skynet_start.c:163#32 0x00007f8482ce8ea5 in start_thread () from /lib64/libpthread.so.0#33 0x00007f84825079fd in clone () from /lib64/libc.so.6

我想确认以下netpack.tostring(msg, sz)不能多次调用么?相关机制是怎样的?

名字: 自动排版 密码:

回复 | (3197) | getit1204 | 2022-07-21 08:03:09