我使用-g標誌和-O0編譯代碼。請參閱下面的valgrind輸出。__libc_freeres()中的空閒()/刪除/刪除[]/realloc()
我只想知道我是否可以看到什麼是無效釋放?我只看到這一點:
==2566== Invalid free()/delete/delete[]/realloc()
==2566== at 0x4A21244: free (vg_replace_malloc.c:468)
==2566== by 0x500FB7A: free_mem (in /lib64/libc-2.4.so)
==2566== by 0x500F781: __libc_freeres (in /lib64/libc-2.4.so)
==2566== by 0x491C719: _vgnU_freeres (vg_preloaded.c:62)
==2566== by 0x4F4E6F4: exit (in /lib64/libc-2.4.so)
==2566== by 0x4F3930A: (below main) (in /lib64/libc-2.4.so)
==2566== Address 0x403ef10 is not stack'd, malloc'd or (recently) free'd
==2566==
==2566==
==2566== HEAP SUMMARY:
==2566== in use at exit: 2,416,506 bytes in 1,844 blocks
==2566== total heap usage: 62,683 allocs, 60,840 frees, 2,957,293 bytes allocated
==2566==
==2566== Searching for pointers to 1,844 not-freed blocks
==2566== Checked 5,445,056 bytes
代碼:
int HoleInstrumentenDiffListeDB(GTree *tree)
{
OCI_Connection* cn;
OCI_Statement* st;
OCI_Resultset* rs;
if (!OCI_Initialize(err_handler, NULL, OCI_ENV_DEFAULT))
return EXIT_FAILURE;
char query[500];
query[0] ='\0';
cn = OCI_ConnectionCreate("db", "u", "p", OCI_SESSION_DEFAULT);
st = OCI_StatementCreate(cn);
strcat(query, "SELECT ...");
OCI_ExecuteStmt(st, query);
rs = OCI_GetResultset(st);
int i = 1;
int j = 0;
char *symbolp;
while (OCI_FetchNext(rs)){
const char * symbolp = OCI_GetString(rs,2);
switch (* OCI_GetString(rs,3))
{
case 'N':
insertQot(tree, symbolp, OCI_GetInt(rs, 1));
printf("new \n");
break;
case 'U':
insertQot(tree, symbolp, OCI_GetInt(rs, 1));
printf("upd \n");
break;
case 'D':
deleteQot(tree, symbolp);
printf("del \n");
break;
}
}
OCI_Cleanup();
return 1;
}
int main()
{
GTree* t = g_tree_new_full((GCompareDataFunc)g_ascii_strcasecmp,NULL,g_free,g_free);
HoleInstrumentenListe(t);
HoleInstrumentenDiffListeDB(t);
g_tree_destroy (t);
}
我們需要看代碼。你可以讓它轉儲調試信息,你可以用gdb進行分析。否則,我們需要看代碼。顯示問題的最小示例,而不是100行。 – Brian
謝謝你的代碼。請再次刪除無助於重現問題的任何無關信息。這裏有很多絨毛。我們不知道如何幫助你。 – Brian
嘗試將'--run-libc-freeres = no'參數添加到'valgrind'中,如http://valgrind.org/docs/manual/manual-core.html#manual-core.rareopts中所述。 – timrau