首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >aerospike_key_get()中的分段错误

aerospike_key_get()中的分段错误
EN

Stack Overflow用户
提问于 2018-06-25 19:56:10
回答 1查看 88关注 0票数 2

我使用的是Aerospike的C客户端库。给定的代码给我带来了很多麻烦:

代码语言:javascript
复制
RtCliErrors RtZonalDao::rtDispZonalCodes(char * p_ZnCodeListName, vector <struct RtDispRgZnCode> & dispRgZnCodeVec)
{
    printf("\n[%s::%d] === Inside rtDispZonalCodes() === \n",__FILE__,__LINE__);

    as_error l_asError;
    as_key l_key ;
    as_record l_rec;

    try{
            if(aerospike_cluster_is_connected(&RtDbConnection::ms_aerospikeIns) == true)
            {
                    printf("\n[%s::%d] === aerospike connection OK ===",__FILE__,__LINE__);
            }
            else{
                    printf("\n[%s::%d] aerospike is not connected",__FILE__,__LINE__);
                    return RT_FAILURE;
            }

            if(p_ZnCodeListName==NULL)
            {
                    printf("\n[%s::%d] Error: Null value of ZnCodeListName \n",__FILE__,__LINE__);
                    return RT_FAILURE;
            }

            if(p_ZnCodeListName!=NULL&&p_ZnCodeListName[0]==0)
            {
                    printf("\n[%s::%d] Error: Null value of ZnCodeListName \n",__FILE__,__LINE__);
                    return RT_FAILURE;
            }

            as_key_init_str(&l_key, "bar", "rg_zn_cd_list_id_name", p_ZnCodeListName);

            printf("\n[%s::%d] Key initialised successfully\n",__FILE__,__LINE__);
            as_record* p_rec=&l_rec;

            if (aerospike_key_exists(&RtDbConnection::ms_aerospikeIns, &l_asError, NULL, &l_key, &p_rec) == AEROSPIKE_ERR_RECORD_NOT_FOUND)
            {
                    as_record_destroy(&l_rec);

                    as_key_destroy(&l_key);

                    printf("\n[ %s::%d ]--> Exception: , RG_ZN_CD_LIST not present in Db\n",__FILE__,__LINE__);

                    return RT_RG_ZN_CD_LST_NOT;
            }

            else
                    printf("\n[%s::%d] Primary Key found\n",__FILE__,__LINE__);
            if (aerospike_key_get(&RtDbConnection::ms_aerospikeIns, &l_asError, NULL, &l_key, &p_rec) != AEROSPIKE_OK)
            {
                    as_record_destroy(&l_rec);

                    as_key_destroy(&l_key);

                    printf("\n[%s::%d] Exception! Error Code: %d, Error Msg: %s\n",__FILE__,__LINE__, l_asError.code, l_asError.message);

                    return RT_FAILURE;

            }


            printf("\n[%s::%d] Fetch success\n",__FILE__,__LINE__);
            as_record_destroy(&l_rec);

            as_key_destroy(&l_key);


            return RT_SUCCESS;

    }//end of try
    catch(...)
    {
            printf("\n[%s::%d] Default Exeption Caught \n",__FILE__,__LINE__);

            as_record_destroy(&l_rec);

            as_key_destroy(&l_key);
            return RT_FAILURE;
    }

}

我已经无计可施了。我一直在尝试找出我的客户端代码中的问题,但仍然没有成功。我得到了奇怪的观察结果。上面的API在第一次被调用时运行良好,但当我第二次调用它时,它给出了分段错误。下面是Valgrind输出的一个片段:

代码语言:javascript
复制
==14471== Conditional jump or move depends on uninitialised value(s)
==14471==    at 0x4A0A965: memcpy (vg_replace_strmem.c:1023)
==14471==    by 0x4E77C4B: as_command_parse_bins (as_command.c:985)
==14471==    by 0x4E7805E: as_command_parse_result (as_command.c:1167)
==14471==    by 0x4E787D2: as_command_execute (as_command.c:492)
==14471==    by 0x4E6DF22: aerospike_key_get (aerospike_key.c:136)
==14471==    by 0x4042D0: RtZonalDao::rtDispZonalCodes(char*, std::vector<RtDispRgZnCode, std::allocator<RtDispRgZnCode> >&) (RtZonalDao.cpp:90)
==14471==    by 0x404679: RtZonalDao::rtAddRgZnCodeToList(RtRgZonalCodes*, char*) (RtZonalDao.cpp:370)
==14471==    by 0x407665: RtZonalDaoTest::rtAdd() (RtZonalDaoTest.cpp:94)
==14471==    by 0x403134: main (RtMain.cpp:194)
==14471==  Uninitialised value was created by a stack allocation
==14471==    at 0x4041A8: RtZonalDao::rtDispZonalCodes(char*, std::vector<RtDispRgZnCode, std::allocator<RtDispRgZnCode> >&) (RtZonalDao.cpp:24)
==14471==
==14471== Use of uninitialised value of size 8
==14471==    at 0x4A0A9AB: memcpy (vg_replace_strmem.c:1023)
==14471==    by 0x4E77C4B: as_command_parse_bins (as_command.c:985)
==14471==    by 0x4E7805E: as_command_parse_result (as_command.c:1167)
==14471==    by 0x4E787D2: as_command_execute (as_command.c:492)
==14471==    by 0x4E6DF22: aerospike_key_get (aerospike_key.c:136)
==14471==    by 0x4042D0: RtZonalDao::rtDispZonalCodes(char*, std::vector<RtDispRgZnCode, std::allocator<RtDispRgZnCode> >&) (RtZonalDao.cpp:90)
==14471==    by 0x404679: RtZonalDao::rtAddRgZnCodeToList(RtRgZonalCodes*, char*) (RtZonalDao.cpp:370)
==14471==    by 0x407665: RtZonalDaoTest::rtAdd() (RtZonalDaoTest.cpp:94)
==14471==    by 0x403134: main (RtMain.cpp:194)
==14471==  Uninitialised value was created by a stack allocation
==14471==    at 0x4041A8: RtZonalDao::rtDispZonalCodes(char*, std::vector<RtDispRgZnCode, std::allocator<RtDispRgZnCode> >&) (RtZonalDao.cpp:24)
==14471==
==14471== Invalid write of size 8
==14471==    at 0x4A0A9AB: memcpy (vg_replace_strmem.c:1023)
==14471==    by 0x4E77C4B: as_command_parse_bins (as_command.c:985)
==14471==    by 0x4E7805E: as_command_parse_result (as_command.c:1167)
==14471==    by 0x4E787D2: as_command_execute (as_command.c:492)
==14471==    by 0x4E6DF22: aerospike_key_get (aerospike_key.c:136)
==14471==    by 0x4042D0: RtZonalDao::rtDispZonalCodes(char*, std::vector<RtDispRgZnCode, std::allocator<RtDispRgZnCode> >&) (RtZonalDao.cpp:90)
==14471==    by 0x404679: RtZonalDao::rtAddRgZnCodeToList(RtRgZonalCodes*, char*) (RtZonalDao.cpp:370)
==14471==    by 0x407665: RtZonalDaoTest::rtAdd() (RtZonalDaoTest.cpp:94)
==14471==    by 0x403134: main (RtMain.cpp:194)
==14471==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==14471==
==14471==
==14471== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==14471==  Access not within mapped region at address 0x0
==14471==    at 0x4A0A9AB: memcpy (vg_replace_strmem.c:1023)
==14471==    by 0x4E77C4B: as_command_parse_bins (as_command.c:985)
==14471==    by 0x4E7805E: as_command_parse_result (as_command.c:1167)
==14471==    by 0x4E787D2: as_command_execute (as_command.c:492)
==14471==    by 0x4E6DF22: aerospike_key_get (aerospike_key.c:136)
==14471==    by 0x4042D0: RtZonalDao::rtDispZonalCodes(char*, std::vector<RtDispRgZnCode, std::allocator<RtDispRgZnCode> >&) 

    (RtZonalDao.cpp:90)
    ==14471==    by 0x404679: RtZonalDao::rtAddRgZnCodeToList(RtRgZonalCodes*, char*) (RtZonalDao.cpp:370)
    ==14471==    by 0x407665: RtZonalDaoTest::rtAdd() (RtZonalDaoTest.cpp:94)
    ==14471==    by 0x403134: main (RtMain.cpp:194)
    ==14471==  If you believe this happened as a result of a stack
    ==14471==  overflow in your program's main thread (unlikely but
    ==14471==  possible), you can try to increase the size of the
    ==14471==  main thread stack using the --main-stacksize= flag.
    ==14471==  The main thread stack size used in this run was 10485760.
    ==14471==
    ==14471== HEAP SUMMARY:
    ==14471==     in use at exit: 248,960 bytes in 70 blocks
    ==14471==   total heap usage: 126 allocs, 56 frees, 260,256 bytes allocated

Is there any problem in any part of the code I’ve provided above?
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-26 07:49:59

似乎在Aerospike forum上也提出了同样的问题,并在那里得到了回答。我建议不要在两个渠道上交叉发布,或者,如果你这样做了,在两边都提供交叉链接。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51022932

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档