同样的程序在Windows下没出过问题,在Linux下偶发性崩溃,我自己也快崩溃了

离水的鱼儿 2019-07-26 08:39:21
Linux错误信息:应该是内存分配错误,但是这怎么定位啊,头大~!,用的开源的mongoose
(gdb) bt
#0 0x00007f5e0724877d in malloc_consolidate () at /usr/lib64/libc.so.6
#1 0x00007f5e0724a385 in _int_malloc () at /usr/lib64/libc.so.6
#2 0x00007f5e0724cfbc in malloc () at /usr/lib64/libc.so.6
#3 0x00007f5e072875c1 in __alloc_dir () at /usr/lib64/libc.so.6
#4 0x00007f5decf7e2a7 in op_get_device_list (_discdevs=0x7ffcab42f6c8, ctx=0x153e7c0) at os/linux_usbfs.c:1164
#5 0x00007f5decf7e2a7 in op_get_device_list (ctx=0x153e7c0, _discdevs=0x7ffcab42f6c8) at os/linux_usbfs.c:1209
#6 0x00007f5decf775b3 in libusb_get_device_list (ctx=0x153e7c0, list=0x7ffcab42f740) at core.c:632
#7 0x00007f5decf764cc in HKEY_Connect () at /usr/lib64/libswskf.so
#8 0x00007f5decf769ee in dev_OpenDev () at /usr/lib64/libswskf.so
#9 0x00007f5decf6e62c in SKF_ConnectDev () at /usr/lib64/libswskf.so
#10 0x00000000004737dd in Synkey_GetEquipmentID(SK_HSKFPROV_PTR, SK_BYTE_PTR, SK_ULONG_PTR, SK_ULONG_PTR) (phProv=0x9c9aa0 <hAppProv>, pEquipID=0x7ffcab42fd70 "", pEquipIDLen=0x7ffcab42fffc, pAlgAsymCap=0x0)
at SKFClient.cpp:3162
#11 0x000000000049ee17 in TASKFRA_AskAppEquipID(std::string, http_message*, mg_connection*, void (*)(mg_connection*, std::string, http_message*)) (url="/api/TASKFRA_AskAppEquipID", http_req=0x7ffcab434500, c=0x153a740, rsp_callback=0x45a908 <HttpServer::SendRsp(mg_connection*, std::string, http_message*)>) at SRPlatform.cpp:3319
#12 0x000000000045ba22 in HttpServer::HandleEvent(mg_connection*, http_message*) (connection=0x153a740, http_req=0x7ffcab434500) at HttpServer.cpp:523
#13 0x000000000045a79b in HttpServer::OnHttpEvent(mg_connection*, int, void*) (connection=0x153a740, event_type=100, event_data=0x7ffcab434500) at HttpServer.cpp:211
#14 0x0000000000414563 in mg_call(mg_connection*, mg_event_handler_t, void*, int, void*) (nc=0x153a740, ev_handler=0x45a716 <HttpServer::OnHttpEvent(mg_connection*, int, void*)>, user_data=0x1, ev=100, ev_data=0x7ffcab434500) at mongoose.c:2506
#15 0x00000000004223eb in mg_http_call_endpoint_handler(mg_connection*, int, http_message*) (nc=0x153a740, ev=100, hm=0x7ffcab434500) at mongoose.c:9165
#16 0x000000000041cafb in mg_http_handler(mg_connection*, int, void*) (nc=0x153a740, ev=3, ev_data=0x7ffcab434b6c) at mongoose.c:6815
#17 0x0000000000414563 in mg_call(mg_connection*, mg_event_handler_t, void*, int, void*) (nc=0x153a740, ev_handler=0x41c283 <mg_http_handler(mg_connection*, int, void*)>, user_data=0x1, ev=3, ev_data=0x7ffcab434b6c) at mongoose.c:2506
#18 0x0000000000415ca2 in mg_recv_tcp(mg_connection*, char*, size_t) (nc=0x153a740, buf=0x1541eb0 "POST /api/TASKFRA_AskAppEquipID HTTP/1.1\r\nHost: 127.0.0.1:38000\r\nUser-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0\r\nAccept: */*\r\nAccept-Language: en-US,en;q=0.5\r\nAccept-"..., len=1460) at mongoose.c:3054
#19 0x0000000000415a2a in mg_do_recv(mg_connection*) (nc=0x153a740) at mongoose.c:3009
#20 0x0000000000415a69 in mg_if_can_recv_cb(mg_connection*) (nc=0x153a740) at mongoose.c:3016
#21 0x00000000004184ae in mg_mgr_handle_conn(mg_connection*, int, double) (nc=0x153a740, fd_flags=1, now=1564143283.8339701) at mongoose.c:4143
#22 0x0000000000418dbd in mg_socket_if_poll(mg_iface*, int) (iface=0x150ac80, timeout_ms=200) at mongoose.c:4334
#23 0x0000000000414ec3 in mg_mgr_poll(mg_mgr*, int) (m=0x150a3b0, timeout_ms=200) at mongoose.c:2711
#24 0x000000000045a6ed in HttpServer::httpsStart(char*, int) (this=0x150a3a0, strPath=0x9990e0 <strPath> "/home/shenxuebing/桌面/service/SRP", logLevel=1) at HttpServer.cpp:191
#25 0x00000000004609c3 in main(int, char**) (argc=1, argv=0x7ffcab4386b8) at HttpServer_Mg.cpp:10619



mongoose申请控件代码:
void mbuf_resize(struct mbuf *a, size_t new_size) WEAK;
void mbuf_resize(struct mbuf *a, size_t new_size) {
if (new_size > a->size || (new_size < a->size && new_size >= a->len)) {
char *buf = (char *) MBUF_REALLOC(a->buf, new_size);
/*
* In case realloc fails, there's not much we can do, except keep things as
* they are. Note that NULL is a valid return value from realloc when
* size == 0, but that is covered too.
*/
if (buf == NULL && new_size != 0) return;
a->buf = buf;
a->size = new_size;
}
}

void mbuf_trim(struct mbuf *mbuf) WEAK;
void mbuf_trim(struct mbuf *mbuf) {
mbuf_resize(mbuf, mbuf->len);
}

size_t mbuf_insert(struct mbuf *a, size_t off, const void *buf, size_t) WEAK;
size_t mbuf_insert(struct mbuf *a, size_t off, const void *buf, size_t len) {
char *p = NULL;

assert(a != NULL);
assert(a->len <= a->size);
assert(off <= a->len);

/* check overflow */
if (~(size_t) 0 - (size_t) a->buf < len) return 0;

if (a->len + len <= a->size) {
memmove(a->buf + off + len, a->buf + off, a->len - off);
if (buf != NULL) {
memcpy(a->buf + off, buf, len);
}
a->len += len;
} else {
size_t min_size = (a->len + len);
size_t new_size = (size_t)(min_size * MBUF_SIZE_MULTIPLIER);
if (new_size - min_size > MBUF_SIZE_MAX_HEADROOM) {
new_size = min_size + MBUF_SIZE_MAX_HEADROOM;
}
p = (char *) MBUF_REALLOC(a->buf, new_size);
if (p == NULL && new_size != min_size) {
new_size = min_size;
p = (char *) MBUF_REALLOC(a->buf, new_size);
}
if (p != NULL) {
a->buf = p;
if (off != a->len) {
memmove(a->buf + off + len, a->buf + off, a->len - off);
}
if (buf != NULL) memcpy(a->buf + off, buf, len);
a->len += len;
a->size = new_size;
} else {
len = 0;
}
}

return len;
}



...全文
186 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
离水的鱼儿 2019-08-09
  • 打赏
  • 举报
回复
引用 2 楼 636f6c696e 的回复:
典型的踩内存问题 把linux的内存管理结构踩了,就会出现这个异常 windows不出不代表windows没问题
越界了,导致后边的程序申请空间的时候发生崩溃。Windows 确实没有这个问题,是在不同平台基础类型大小不一样导致的。空间分大点就好了。
636f6c696e 2019-08-09
  • 打赏
  • 举报
回复
典型的踩内存问题 把linux的内存管理结构踩了,就会出现这个异常 windows不出不代表windows没问题
离水的鱼儿 2019-08-08
  • 打赏
  • 举报
回复
早就解决了,反正没人回帖,结了。

69,382

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧