我正在尝试执行一个与mysql交互的非常基本的c程序。我实现了mysql connector/c教程的最开始部分,但是当我尝试执行该代码时,总是遇到一个错误。下面是我要执行的代码:
try
{
sql::mysql::MySQL_Driver *driver = NULL;
sql::Connection *conn = NULL;
driver = sql::mysql::get_mysql_driver_instance();
if (driver != NULL)
{
conn = driver->connect("127.0.0.1:3306", "root", "root");
cout << "Test" << endl;
}
delete conn;
conn = NULL;
}
当我执行这段代码时,“test”被打印出来,但是我得到了以下错误:
***Error in `./test': free(): invalid pointer: 0x00007f0a9a292158***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7f0a999a87e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7f0a999b137a]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7f0a999b553c]
./test(_ZN3sql9SQLStringD1Ev+0x18)[0x401296]
/lib/x86_64-linux-gnu/libc.so.6(+0x39ff8)[0x7f0a9996aff8]
/lib/x86_64-linux-gnu/libc.so.6(+0x3a045)[0x7f0a9996b045]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf7)[0x7f0a99951837]
./test[0x400e79]
======= Memory map: ========
00400000-00402000 r-xp 00000000 08:01 6167619
/home/lichtsb1/local/src/ddsWork/mysqlTest/test
00601000-00602000 r--p 00001000 08:01 6167619
/home/lichtsb1/local/src/ddsWork/mysqlTest/test
00602000-00603000 rw-p 00002000 08:01 6167619
/home/lichtsb1/local/src/ddsWork/mysqlTest/test
02357000-023aa000 rw-p 00000000 00:00 0
[heap]
7f0a94000000-7f0a94021000 rw-p 00000000 00:00 0
7f0a94021000-7f0a98000000 ---p 00000000 00:00 0
7f0a989a8000-7f0a98ab0000 r-xp 00000000 08:01 43253857
/lib/x86_64-linux-gnu/libm-2.23.so
7f0a98ab0000-7f0a98caf000 ---p 00108000 08:01 43253857
/lib/x86_64-linux-gnu/libm-2.23.so
7f0a98caf000-7f0a98cb0000 r--p 00107000 08:01 43253857
/lib/x86_64-linux-gnu/libm-2.23.so
7f0a98cb0000-7f0a98cb1000 rw-p 00108000 08:01 43253857
/lib/x86_64-linux-gnu/libm-2.23.so
7f0a98cb1000-7f0a98cb4000 r-xp 00000000 08:01 43254080
/lib/x86_64-linux-gnu/libdl-2.23.so
7f0a98cb4000-7f0a98eb3000 ---p 00003000 08:01 43254080
/lib/x86_64-linux-gnu/libdl-2.23.so
7f0a98eb3000-7f0a98eb4000 r--p 00002000 08:01 43254080
/lib/x86_64-linux-gnu/libdl-2.23.so
7f0a98eb4000-7f0a98eb5000 rw-p 00003000 08:01 43254080
/lib/x86_64-linux-gnu/libdl-2.23.so
7f0a98eb5000-7f0a99074000 r-xp 00000000 08:01 7733609
/home/lichtsb1/local/src/ddsWork/mysqlTest/mysql-connector-c++-8.0.13-linux-glibc2.12-x86-64bit/lib64/libcrypto.so.1.0.0
7f0a99074000-7f0a99273000 ---p 001bf000 08:01 7733609
/home/lichtsb1/local/src/ddsWork/mysqlTest/mysql-connector-c++-8.0.13-linux-glibc2.12-x86-64bit/lib64/libcrypto.so.1.0.0
7f0a99273000-7f0a9929a000 rw-p 001be000 08:01 7733609
/home/lichtsb1/local/src/ddsWork/mysqlTest/mysql-connector-c++-8.0.13-linux-glibc2.12-x86-64bit/lib64/libcrypto.so.1.0.0
7f0a9929a000-7f0a9929d000 rw-p 00000000 00:00 0
7f0a9929d000-7f0a99302000 r-xp 00000000 08:01 7733606
/home/lichtsb1/local/src/ddsWork/mysqlTest/mysql-connector-c++-8.0.13-linux-glibc2.12-x86-64bit/lib64/libssl.so.1.0.0
7f0a99302000-7f0a99502000 ---p 00065000 08:01 7733606
/home/lichtsb1/local/src/ddsWork/mysqlTest/mysql-connector-c++-8.0.13-linux-glibc2.12-x86-64bit/lib64/libssl.so.1.0.0
7f0a99502000-7f0a9950c000 rw-p 00065000 08:01 7733606
/home/lichtsb1/local/src/ddsWork/mysqlTest/mysql-connector-c++-8.0.13-linux-glibc2.12-x86-64bit/lib64/libssl.so.1.0.0
7f0a9950c000-7f0a99513000 r-xp 00000000 08:01 43254289
/lib/x86_64-linux-gnu/librt-2.23.so
7f0a99513000-7f0a99712000 ---p 00007000 08:01 43254289
/lib/x86_64-linux-gnu/librt-2.23.so
7f0a99712000-7f0a99713000 r--p 00006000 08:01 43254289
/lib/x86_64-linux-gnu/librt-2.23.so
7f0a99713000-7f0a99714000 rw-p 00007000 08:01 43254289
/lib/x86_64-linux-gnu/librt-2.23.so
7f0a99714000-7f0a9972c000 r-xp 00000000 08:01 43253992
/lib/x86_64-linux-gnu/libpthread-2.23.so
7f0a9972c000-7f0a9992b000 ---p 00018000 08:01 43253992
/lib/x86_64-linux-gnu/libpthread-2.23.so
7f0a9992b000-7f0a9992c000 r--p 00017000 08:01 43253992
/lib/x86_64-linux-gnu/libpthread-2.23.so
7f0a9992c000-7f0a9992d000 rw-p 00018000 08:01 43253992
/lib/x86_64-linux-gnu/libpthread-2.23.so
7f0a9992d000-7f0a99931000 rw-p 00000000 00:00 0
7f0a99931000-7f0a99af1000 r-xp 00000000 08:01 43254051
/lib/x86_64-linux-gnu/libc-2.23.so
7f0a99af1000-7f0a99cf1000 ---p 001c0000 08:01 43254051
/lib/x86_64-linux-gnu/libc-2.23.so
7f0a99cf1000-7f0a99cf5000 r--p 001c0000 08:01 43254051
/lib/x86_64-linux-gnu/libc-2.23.so
7f0a99cf5000-7f0a99cf7000 rw-p 001c4000 08:01 43254051
/lib/x86_64-linux-gnu/libc-2.23.so
7f0a99cf7000-7f0a99cfb000 rw-p 00000000 00:00 0
7f0a99cfb000-7f0a99d11000 r-xp 00000000 08:01 43254905
/lib/x86_64-linux-gnu/libgcc_s.so.1
7f0a99d11000-7f0a99f10000 ---p 00016000 08:01 43254905
/lib/x86_64-linux-gnu/libgcc_s.so.1
7f0a99f10000-7f0a99f11000 rw-p 00015000 08:01 43254905
/lib/x86_64-linux-gnu/libgcc_s.so.1
7f0a99f11000-7f0a9a083000 r-xp 00000000 08:01 20972156
/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f0a9a083000-7f0a9a283000 ---p 00172000 08:01 20972156
/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f0a9a283000-7f0a9a28d000 r--p 00172000 08:01 20972156
/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f0a9a28d000-7f0a9a28f000 rw-p 0017c000 08:01 20972156
/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f0a9a28f000-7f0a9a293000 rw-p 00000000 00:00 0
7f0a9a293000-7f0a9a6ed000 r-xp 00000000 08:01 7733614
/home/lichtsb1/local/src/ddsWork/mysqlTest/mysql-connector-c++-8.0.13-linux-glibc2.12-x86-64bit/lib64/libmysqlcppconn.so.7.8.0.13
7f0a9a6ed000-7f0a9a8ed000 ---p 0045a000 08:01 7733614
/home/lichtsb1/local/src/ddsWork/mysqlTest/mysql-connector-c++-8.0.13-linux-glibc2.12-x86-64bit/lib64/libmysqlcppconn.so.7.8.0.13
7f0a9a8ed000-7f0a9a8f8000 r--p 0045a000 08:01 7733614
/home/lichtsb1/local/src/ddsWork/mysqlTest/mysql-connector-c++-8.0.13-linux-glibc2.12-x86-64bit/lib64/libmysqlcppconn.so.7.8.0.13
7f0a9a8f8000-7f0a9aab7000 rw-p 00465000 08:01 7733614
/home/lichtsb1/local/src/ddsWork/mysqlTest/mysql-connector-c++-8.0.13-linux-glibc2.12-x86-64bit/lib64/libmysqlcppconn.so.7.8.0.13
7f0a9aab7000-7f0a9aabd000 rw-p 00000000 00:00 0
7f0a9aabd000-7f0a9aae3000 r-xp 00000000 08:01 43253979
/lib/x86_64-linux-gnu/ld-2.23.so
7f0a9ac7b000-7f0a9acb7000 r--s 00000000 08:01 16523805
/var/cache/nscd/services
7f0a9acb7000-7f0a9acbe000 rw-p 00000000 00:00 0
7f0a9ace0000-7f0a9ace2000 rw-p 00000000 00:00 0
7f0a9ace2000-7f0a9ace3000 r--p 00025000 08:01 43253979
/lib/x86_64-linux-gnu/ld-2.23.so
7f0a9ace3000-7f0a9ace4000 rw-p 00026000 08:01 43253979
/lib/x86_64-linux-gnu/ld-2.23.so
7f0a9ace4000-7f0a9ace5000 rw-p 00000000 00:00 0
7ffe3b05c000-7ffe3b07e000 rw-p 00000000 00:00 0
[stack]
7ffe3b0dd000-7ffe3b0e0000 r--p 00000000 00:00 0
[vvar]
7ffe3b0e0000-7ffe3b0e2000 r-xp 00000000 00:00 0
[vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0
[vsyscall]
Aborted (core dumped)
这太基本了-我做错什么了?
非常感谢你的帮助。
暂无答案!
目前还没有任何答案,快来回答吧!