[zeromq-dev] zmq_msg_close() change other pointer

某 G zbgaoyuhao at hotmail.com
Tue Oct 10 04:31:59 CEST 2017


Hi,

I got an free() error when I use it after zmq_msg_close(). It really changed my pointer. It was so strange! Anyone can help me? The whole code is in https://pastebin.com/M7k4xPEP .


        rawData = zmq_msg_data(&msg);
        readptr = malloc(msgLen);
        ptr_recorder = readptr;
        if(readptr != ptr_recorder)
        {
            printf("sth wrong!!!! #0\n");
        }


        memset(readptr, 0, msgLen);

        if(readptr != ptr_recorder)
        {
            printf("sth wrong!!!! #1\n");
        }

        memcpy(readptr,rawData,msgLen);

        if(readptr != ptr_recorder)
        {
            printf("sth wrong!!!! #21\n");
        }

        zmq_msg_close (&msg);                //  From here, readptr != ptr_recorder , but why ?????

        if(readptr != ptr_recorder)
        {
            printf("sth wrong!!!! #22\n");  // I got this.
        }


        WriteData(cacheContext, size, readptr);

        if(readptr != ptr_recorder)
        {
            printf("sth wrong!!!! #23\n"); // I got this too.
        }

        free(readptr);

 And then I got:

*** Error in `./CapConnTest': free(): invalid pointer: 0x00007f3d2511aeac ***
======= Backtrace: =========
/lib64/libc.so.6(+0x7c503)[0x7f3d378b2503]
/usr/local/lib/libzmq.so.5(+0x2d065)[0x7f3d375e0065]
/project/libCapConn/libCapConn.so(ZMQClientFragment+0x1ca)[0x7f3d37e14ffd]
/lib64/libpthread.so.0(+0x7dc5)[0x7f3d37bfedc5]
/lib64/libc.so.6(clone+0x6d)[0x7f3d3792d76d]
======= Memory map: ========
00400000-00402000 r-xp 00000000 fd:00 39634684                           /project/capconntest/CapConnTest/build/CapConnTest
00601000-00602000 r--p 00001000 fd:00 39634684                           /project/capconntest/CapConnTest/build/CapConnTest
00602000-00603000 rw-p 00002000 fd:00 39634684                           /project/capconntest/CapConnTest/build/CapConnTest
01f52000-01f73000 rw-p 00000000 00:00 0                                  [heap]
7f3d20000000-7f3d23ffd000 rw-p 00000000 00:00 0
7f3d23ffd000-7f3d24000000 ---p 00000000 00:00 0
7f3d24000000-7f3d25139000 rw-p 00000000 00:00 0
7f3d25139000-7f3d28000000 ---p 00000000 00:00 0
7f3d28000000-7f3d2a27f000 rw-p 00000000 00:00 0
7f3d2a27f000-7f3d2c000000 ---p 00000000 00:00 0
7f3d2c000000-7f3d2fffd000 rw-p 00000000 00:00 0
7f3d2fffd000-7f3d30000000 ---p 00000000 00:00 0
7f3d30000000-7f3d30a00000 rw-p 00000000 00:00 0
7f3d30a00000-7f3d34000000 ---p 00000000 00:00 0
7f3d34983000-7f3d34984000 ---p 00000000 00:00 0
7f3d34984000-7f3d35184000 rw-p 00000000 00:00 0                          [stack:18934]
7f3d35184000-7f3d35185000 ---p 00000000 00:00 0
7f3d35185000-7f3d35985000 rw-p 00000000 00:00 0                          [stack:18933]
7f3d35985000-7f3d35986000 ---p 00000000 00:00 0
7f3d35986000-7f3d36186000 rw-p 00000000 00:00 0                          [stack:18932]
7f3d36186000-7f3d36187000 ---p 00000000 00:00 0
7f3d36187000-7f3d36987000 rw-p 00000000 00:00 0                          [stack:18931]
7f3d36987000-7f3d3699c000 r-xp 00000000 fd:00 34087611                   /usr/lib64/libgcc_s-4.8.5-20150702.so.1
7f3d3699c000-7f3d36b9b000 ---p 00015000 fd:00 34087611                   /usr/lib64/libgcc_s-4.8.5-20150702.so.1
7f3d36b9b000-7f3d36b9c000 r--p 00014000 fd:00 34087611                   /usr/lib64/libgcc_s-4.8.5-20150702.so.1
7f3d36b9c000-7f3d36b9d000 rw-p 00015000 fd:00 34087611                   /usr/lib64/libgcc_s-4.8.5-20150702.so.1
7f3d36b9d000-7f3d36c9d000 r-xp 00000000 fd:00 33555898                   /usr/lib64/libm-2.17.so
7f3d36c9d000-7f3d36e9d000 ---p 00100000 fd:00 33555898                   /usr/lib64/libm-2.17.so
7f3d36e9d000-7f3d36e9e000 r--p 00100000 fd:00 33555898                   /usr/lib64/libm-2.17.so
7f3d36e9e000-7f3d36e9f000 rw-p 00101000 fd:00 33555898                   /usr/lib64/libm-2.17.so
7f3d36e9f000-7f3d36f88000 r-xp 00000000 fd:00 33556209                   /usr/lib64/libstdc++.so.6.0.19
7f3d36f88000-7f3d37188000 ---p 000e9000 fd:00 33556209                   /usr/lib64/libstdc++.so.6.0.19
7f3d37188000-7f3d37190000 r--p 000e9000 fd:00 33556209                   /usr/lib64/libstdc++.so.6.0.19
7f3d37190000-7f3d37192000 rw-p 000f1000 fd:00 33556209                   /usr/lib64/libstdc++.so.6.0.19
7f3d37192000-7f3d371a7000 rw-p 00000000 00:00 0
7f3d371a7000-7f3d371a9000 r-xp 00000000 fd:00 33555896                   /usr/lib64/libdl-2.17.so
7f3d371a9000-7f3d373a9000 ---p 00002000 fd:00 33555896                   /usr/lib64/libdl-2.17.so
7f3d373a9000-7f3d373aa000 r--p 00002000 fd:00 33555896                   /usr/lib64/libdl-2.17.so
7f3d373aa000-7f3d373ab000 rw-p 00003000 fd:00 33555896                   /usr/lib64/libdl-2.17.so
7f3d373ab000-7f3d373b2000 r-xp 00000000 fd:00 35535925                   /usr/lib64/librt-2.17.so
7f3d373b2000-7f3d375b1000 ---p 00007000 fd:00 35535925                   /usr/lib64/librt-2.17.so
7f3d375b1000-7f3d375b2000 r--p 00006000 fd:00 35535925                   /usr/lib64/librt-2.17.so
7f3d375b2000-7f3d375b3000 rw-p 00007000 fd:00 35535925                   /usr/lib64/librt-2.17.so
7f3d375b3000-7f3d37630000 r-xp 00000000 fd:00 100818039                  /usr/local/lib/libzmq.so.5.1.2
7f3d37630000-7f3d3782f000 ---p 0007d000 fd:00 100818039                  /usr/local/lib/libzmq.so.5.1.2
7f3d3782f000-7f3d37835000 r--p 0007c000 fd:00 100818039                  /usr/local/lib/libzmq.so.5.1.2
7f3d37835000-7f3d37836000 rw-p 00082000 fd:00 100818039                  /usr/local/lib/libzmq.so.5.1.2
7f3d37836000-7f3d379ed000 r-xp 00000000 fd:00 33555890                   /usr/lib64/libc-2.17.so
7f3d379ed000-7f3d37bec000 ---p 001b7000 fd:00 33555890                   /usr/lib64/libc-2.17.so
7f3d37bec000-7f3d37bf0000 r--p 001b6000 fd:00 33555890                   /usr/lib64/libc-2.17.so
7f3d37bf0000-7f3d37bf2000 rw-p 001ba000 fd:00 33555890                   /usr/lib64/libc-2.17.so
7f3d37bf2000-7f3d37bf7000 rw-p 00000000 00:00 0
7f3d37bf7000-7f3d37c0e000 r-xp 00000000 fd:00 35535921                   /usr/lib64/libpthread-2.17.so
7f3d37c0e000-7f3d37e0d000 ---p 00017000 fd:00 35535921                   /usr/lib64/libpthread-2.17.so
7f3d37e0d000-7f3d37e0e000 r--p 00016000 fd:00 35535921                   /usr/lib64/libpthread-2.17.so
7f3d37e0e000-7f3d37e0f000 rw-p 00017000 fd:00 35535921                   /usr/lib64/libpthread-2.17.so
7f3d37e0f000-7f3d37e13000 rw-p 00000000 00:00 0
7f3d37e13000-7f3d37e17000 r-xp 00000000 fd:00 68972868                   /project/libCapConn/libCapConn.so
7f3d37e17000-7f3d38016000 ---p 00004000 fd:00 68972868                   /project/libCapConn/libCapConn.so
7f3d38016000-7f3d38017000 r--p 00003000 fd:00 68972868                   /project/libCapConn/libCapConn.so
7f3d38017000-7f3d38018000 rw-p 00004000 fd:00 68972868                   /project/libCapConn/libCapConn.so
7f3d38018000-7f3d38038000 r-xp 00000000 fd:00 34023174                   /usr/lib64/ld-2.17.so
7f3d38219000-7f3d38221000 rw-p 00000000 00:00 0
7f3d38234000-7f3d38238000 rw-p 00000000 00:00 0
7f3d38238000-7f3d38239000 r--p 00020000 fd:00 34023174                   /usr/lib64/ld-2.17.so
7f3d38239000-7f3d3823a000 rw-p 00021000 fd:00 34023174                   /usr/lib64/ld-2.17.so
7f3d3823a000-7f3d3823b000 rw-p 00000000 00:00 0
7ffcd7cd0000-7ffcd7cf1000 rw-p 00000000 00:00 0                          [stack]
7ffcd7dbf000-7ffcd7dc1000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]


Thanks,
Peter Black
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20171010/c7a9e86c/attachment.htm>


More information about the zeromq-dev mailing list