Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetInt coredump #729

Open
lonelymemo opened this issue Sep 2, 2016 · 8 comments
Open

GetInt coredump #729

lonelymemo opened this issue Sep 2, 2016 · 8 comments
Labels

Comments

@lonelymemo
Copy link

这是我的代码(原谅没有试用FindMember来获取,偷懒测试)
if(root.Parse(result.c_str()).HasParseError())
{
WRN("parse json got err %d.\n",root.GetParseError());
return -1;
}
if (root[“retcode”]!= 0) { //core 在这一行,
WRN("curl retcode=%d errmsg=%s\n", root[“retcode”], root["errmsg"].GetString());
return -1;
}
gdb 显示的结果:#0 0x000000000041cfb6 in rapidjson::GenericValuerapidjson::UTF8<char, rapidjson::MemoryPoolAllocatorrapidjson::CrtAllocator >::GetInt (
this=0x10) at rapidjson/document.h:1645 //这里段错误
照源码来看,无论如何也不应该是段错误,如果json里面没有‘retcode’或者‘retcode’类型不是int,都应该在RAPIDJSON_ASSERT上core(实际上json是有这个字段的,并且类型也是int)。
这里到底是什么原因导致的呢?请教
附:json
{
"errmsg": "Transportendpointisnotconnected",
"results": [
null
],
"retcode": -1
}

@miloyip
Copy link
Collaborator

miloyip commented Sep 2, 2016

不能重现:

#include "rapidjson/document.h"
#include <cstdio>

using namespace rapidjson;

int main() {
    const char json[] = "{\"errmsg\":\"Transportendpointisnotconnected\",\"results\":[null],\"retcode\":-1}";
    Document root;
    root.Parse(json);
    if (root["retcode"] != 0) {
        printf("curl retcode=%d errmsg=%s\n", root["retcode"].GetInt(), root["errmsg"].GetString());
    }
}
$ g++ -I ~/github/rapidjson/include a.cpp
$ ./a.out
curl retcode=-1 errmsg=Transportendpointisnotconnected

@lonelymemo
Copy link
Author

lonelymemo commented Sep 2, 2016

我自己也被迷惑了,不知道是不是其他的原因导致的;目前从coredump看到的情况是这样的。gdb 结果
Program terminated with signal 11, Segmentation fault.
#0 0x000000000041cfb6 in rapidjson::GenericValuerapidjson::UTF8<char, rapidjson::MemoryPoolAllocatorrapidjson::CrtAllocator >::GetInt (
this=0x10) at rapidjson/document.h:1645
1645 rapidjson/document.h: No such file or directory.
Missing separate debuginfos, use: debuginfo-install cyrus-sasl-lib-2.1.26-17.el7.x86_64 glibc-2.17-55.tl2.7.x86_64 keyutils-libs-1.5.8-3.el7.x86_64 krb5-libs-1.11.3-49.el7.x86_64 libcom_err-1.42.9-4.el7.x86_64 libcurl-7.29.0-19.el7.x86_64 libgcc-4.8.2-16.2.el7_0.x86_64 libidn-1.28-3.el7.x86_64 libselinux-2.2.2-6.el7.x86_64 libssh2-1.4.3-8.el7.x86_64 libstdc++-4.8.2-16.2.el7_0.x86_64 mariadb-libs-5.5.41-2.el7_0.x86_64 nspr-4.10.6-1.el7_0.x86_64 nss-3.16.2.3-2.el7_0.x86_64 nss-softokn-freebl-3.16.2.3-1.el7_0.x86_64 nss-util-3.16.2.3-1.el7_0.x86_64 openldap-2.4.39-3.el7.x86_64 openssl-libs-1.0.1e-51.tl2.5.x86_64 pcre-8.32-12.el7.x86_64 xz-libs-5.1.2-8alpha.el7.x86_64 zlib-1.2.7-13.el7.x86_64
(gdb) bt
#0 0x000000000041cfb6 in rapidjson::GenericValuerapidjson::UTF8<char, rapidjson::MemoryPoolAllocatorrapidjson::CrtAllocator >::GetInt (
this=0x10) at rapidjson/document.h:1645
#1 0x0000000000439016 in Dispatch_Proc::get_featuredata_by_id (this=0x7ffdcf006760,
apisvr="http://anm.interface1.oa.com/cgi-bin/netman2.0/core_v2/getfeaturedatabyid_inbulk_v2.cgi",
params="user_id=15&user_rtx=devinzeng&data={%22features%22:[{%22id%22:2037343130,%22day%22:%222016-09-01%22},{%22id%22:2037343131,%22day%22:%222016-09-01%22},{%22id%22:2037343021,%22day%22:%222016-09-01%22},{"..., timesecond=1472724048, last_update_time=1472723448)
at dispatch_proc.cpp:2069
#2 0x0000000000448dc8 in Dispatch_Proc::update_zone (this=0x7ffdcf006760) at dispatch_proc.cpp:2233
#3 0x0000000000449d49 in Dispatch_Proc::calc_video_gslb (this=0x7ffdcf006760) at dispatch_proc.cpp:2454
#4 0x000000000044b433 in Dispatch_Proc::run (this=0x7ffdcf006760) at dispatch_proc.cpp:4058
#5 0x000000000047a0a1 in main (ac=3, av=0x7ffdcf008208) at dispatch_svr.cpp:67
(gdb) f 1
#1 0x0000000000439016 in Dispatch_Proc::get_featuredata_by_id (this=0x7ffdcf006760,
apisvr="http://anm.interface1.oa.com/cgi-bin/netman2.0/core_v2/getfeaturedatabyid_inbulk_v2.cgi",
params="user_id=15&user_rtx=devinzeng&data={%22features%22:[{%22id%22:2037343130,%22day%22:%222016-09-01%22},{%22id%22:2037343131,%22day%22:%222016-09-01%22},{%22id%22:2037343021,%22day%22:%222016-09-01%22},{"..., timesecond=1472724048, last_update_time=1472723448)
at dispatch_proc.cpp:2069
2069 dispatch_proc.cpp: No such file or directory.
(gdb) p result
$1 = "{"errmsg":"Transport endpoint is not connected","results":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,n"...
(gdb) p root
$2 = {rapidjson::GenericValue<rapidjson::UTF8<char, rapidjson::MemoryPoolAllocatorrapidjson::CrtAllocator >> = {
static kDefaultArrayCapacity = <error reading variable: No global symbol "rapidjson::GenericValue<rapidjson::UTF8, rapidjson::MemoryPoolAllocatorrapidjson::CrtAllocator >::kDefaultArrayCapacity".>,
static kDefaultObjectCapacity = <error reading variable: No global symbol "rapidjson::GenericValue<rapidjson::UTF8, rapidjson::MemoryPoolAllocatorrapidjson::CrtAllocator >::kDefaultObjectCapacity".>, data_ = {s = {length = 3, hashcode = 3,
str = 0x3000082d7f370 <Address 0x3000082d7f370 out of bounds>}, ss = {str = "\003\000\000\000\003\000\000\000p\363\327\202\000"}, n = {
i = {i = 3, padding = "\003\000\000"}, u = {u = 3, padding2 = "\003\000\000"}, i64 = 12884901891, u64 = 12884901891,
d = 6.3659873743780139e-314}, o = {size = 3, capacity = 3, members = 0x3000082d7f370}, a = {size = 3, capacity = 3,
elements = 0x3000082d7f370}, f = {payload = "\003\000\000\000\003\000\000\000p\363\327\202\000", flags = 3}}},
static kDefaultStackCapacity = 1024, allocator_ = 0x7d924a70, ownAllocator_ = 0x7d924a70, stack_ = {allocator_ = 0x28631f0,
ownAllocator_ = 0x28631f0, stack_ = 0x0, stackTop_ = 0x0, stackEnd_ = 0x0, initialCapacity_ = 1024}, parseResult_ = {
code_ = rapidjson::kParseErrorNone, offset_ = 0}}
(gdb) se
search section select-frame set
(gdb) set print elements 0
(gdb) p result
$3 = "{"errmsg":"Transport endpoint is not connected","results":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"retcode":-1}\n"
(gdb)

@miloyip
Copy link
Collaborator

miloyip commented Sep 2, 2016

this=0x10 是错的指针。会不会是 root 的生命周期有问题?

@lonelymemo
Copy link
Author

root是一个局部变量,函数调用时申请的,非指针不存在提前释放。

@miloyip
Copy link
Collaborator

miloyip commented Sep 2, 2016

你试试 valgrind 跑一下,看看有没有非法的内存访问?

@lonelymemo
Copy link
Author

嗯,正准备搞一搞试试

@miloyip
Copy link
Collaborator

miloyip commented Sep 16, 2016

有进展么?

@nuoqish
Copy link

nuoqish commented Sep 4, 2017

我也遇到同样的问题,当rapidjson和libcurl同时使用时会随机coredump,目前还在找原因,不知道有没有最新进展?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants