Hello forum,
I compiled and installed POCO 1.4.4 on CentOS 5.7. Compiler version is
gcc version 4.1.2 20080704 (Red Hat 4.1.2-52).
I was able to run the 'dict' example below in the samples folder. It printed out
messages retrieved from the remote site and passed debugging point1 and point2
near the end of the program.
However, when the program is done, it gives the following error which implies memory
corruption and pointer issues:
Any ideas why this happened?
Thank you.
-------------------------------------------------------------------------------------------------------------
//Listing 1
#include "Poco/Net/StreamSocket.h"
#include "Poco/Net/SocketStream.h"
#include "Poco/Net/SocketAddress.h"
#include "Poco/StreamCopier.h"
#include "Poco/Path.h"
#include "Poco/Exception.h"
#include <iostream>
using Poco::Net::StreamSocket;
using Poco::Net::SocketStream;
using Poco::Net::SocketAddress;
using Poco::StreamCopier;
using Poco::Path;
using Poco::Exception;
int main(int argc, char** argv)
{
const std::string HOST("dict.org");
const unsigned short PORT = 2628;
if (argc != 2)
{
Path p(argv[0]);
std::cout << "usage: " << p.getBaseName() << " <term>" << std::endl;
std::cout << " looks up <term> in dict.org and prints the results" << std::endl;
return 1;
}
std::string term(argv[1]);
try
{
SocketAddress sa(HOST, PORT);
StreamSocket sock(sa);
SocketStream str(sock);
str << "DEFINE ! " << term << "\r\n" << std::flush;
str << "QUIT\r\n" << std::flush;
sock.shutdownSend();
StreamCopier::copyStream(str, std::cout);
std::cout << "Point 1" << std::endl;
//return 0;
}
catch (Exception& exc)
{
std::cerr << exc.displayText() << std::endl;
return 1;
}
std::cout << "Point 2" << std::endl;
return 0;
}
--------------------------------------------------------------------------------------------------------------------------
//Listing 2
... ...
250 ok [d/m/c = 1/0/17; 0.000r 0.000u 0.000s]
221 bye [d/m/c = 0/0/0; 0.000r 0.000u 0.000s]
Point 1
Point 2
*** glibc detected *** ./mypoco: double free or corruption (!prev): 0x000000000c44ca60 ***
======= Backtrace: =========
/lib64/libc.so.6[0x3a28e711df]
/lib64/libc.so.6(cfree+0x4b)[0x3a28e7163b]
/usr/lib64/libstdc++.so.6(_ZNSsD1Ev+0x3a)[0x3a3b49dbca]
/usr/local/lib/libPocoNetd.so.14[0x2af2e4237edc]
/lib64/libc.so.6(__cxa_finalize+0x8e)[0x3a28e337fe]
/usr/local/lib/libPocoNetd.so.14[0x2af2e4236296]
======= Memory map: ========
00400000-00402000 r-xp 00000000 fd:00 7394379 /root/playground/Debug/mypoco
00602000-00603000 rw-p 00002000 fd:00 7394379 /root/playground/Debug/mypoco
0c418000-0c45a000 rw-p 0c418000 00:00 0 [heap]
3a28a00000-3a28a1c000 r-xp 00000000 fd:00 6508170 /lib64/ld-2.5.so
3a28c1c000-3a28c1d000 r--p 0001c000 fd:00 6508170 /lib64/ld-2.5.so
3a28c1d000-3a28c1e000 rw-p 0001d000 fd:00 6508170 /lib64/ld-2.5.so
3a28e00000-3a28f4e000 r-xp 00000000 fd:00 6508282 /lib64/libc-2.5.so
3a28f4e000-3a2914d000 ---p 0014e000 fd:00 6508282 /lib64/libc-2.5.so
3a2914d000-3a29151000 r--p 0014d000 fd:00 6508282 /lib64/libc-2.5.so
3a29151000-3a29152000 rw-p 00151000 fd:00 6508282 /lib64/libc-2.5.so
3a29152000-3a29157000 rw-p 3a29152000 00:00 0
3a29200000-3a29282000 r-xp 00000000 fd:00 6508283 /lib64/libm-2.5.so
3a29282000-3a29481000 ---p 00082000 fd:00 6508283 /lib64/libm-2.5.so
3a29481000-3a29482000 r--p 00081000 fd:00 6508283 /lib64/libm-2.5.so
3a29482000-3a29483000 rw-p 00082000 fd:00 6508283 /lib64/libm-2.5.so
3a29600000-3a29602000 r-xp 00000000 fd:00 6508157 /lib64/libdl-2.5.so
3a29602000-3a29802000 ---p 00002000 fd:00 6508157 /lib64/libdl-2.5.so
3a29802000-3a29803000 r--p 00002000 fd:00 6508157 /lib64/libdl-2.5.so
3a29803000-3a29804000 rw-p 00003000 fd:00 6508157 /lib64/libdl-2.5.so
3a29a00000-3a29a16000 r-xp 00000000 fd:00 6508291 /lib64/libpthread-2.5.so
3a29a16000-3a29c15000 ---p 00016000 fd:00 6508291 /lib64/libpthread-2.5.so
3a29c15000-3a29c16000 r--p 00015000 fd:00 6508291 /lib64/libpthread-2.5.so
3a29c16000-3a29c17000 rw-p 00016000 fd:00 6508291 /lib64/libpthread-2.5.so
3a29c17000-3a29c1b000 rw-p 3a29c17000 00:00 0
3a2a200000-3a2a207000 r-xp 00000000 fd:00 6508302 /lib64/librt-2.5.so
3a2a207000-3a2a407000 ---p 00007000 fd:00 6508302 /lib64/librt-2.5.so
3a2a407000-3a2a408000 r--p 00007000 fd:00 6508302 /lib64/librt-2.5.so
3a2a408000-3a2a409000 rw-p 00008000 fd:00 6508302 /lib64/librt-2.5.so
3a32000000-3a32011000 r-xp 00000000 fd:00 6508304 /lib64/libresolv-2.5.so
3a32011000-3a32211000 ---p 00011000 fd:00 6508304 /lib64/libresolv-2.5.so
3a32211000-3a32212000 r--p 00011000 fd:00 6508304 /lib64/libresolv-2.5.so
3a32212000-3a3Aborted
--------------------------------------------------------------------------------------------------------------------------





