无效免费()/删除/在__libc_freeres删除[] / realloc的()() [英] Invalid free() / delete / delete[] / realloc() in __libc_freeres()
问题描述
我编译code。与-g标志和-O0。请参考下面的valgrind输出。
我只是想知道我是否我可以看到什么是无效的束缚中解脱出来?我只看到这一点:
== == 2566免费无效()/删除/删除[] / realloc的()
== == 2566在0x4A21244:免费(vg_replace_malloc.c:468)
== == 2566通过0x500FB7A:FREE_MEM(以/lib64/libc-2.4.so)
== == 2566年通过0x500F781:__libc_freeres(以/lib64/libc-2.4.so)
== == 2566通过0x491C719:_vgnU_freeres(vg_ preloaded.c:62)
== == 2566通过0x4F4E6F4:出口(在/lib64/libc-2.4.so)
== == 2566由0x4F3930A:(如下主要)(以/lib64/libc-2.4.so)
== == 2566地址0x403ef10不stack'd,malloc分配或(最近)free'd
== == 2566
== == 2566
== == 2566 HEAP摘要:
== == 2566使用在出口处:在1844块2416506字节
== == 2566总堆的使用情况:62683 allocs,60840的FreeS,2957293字节分配
== == 2566
== == 2566搜索指针1844未释放的块
== == 2566托运5445056字节
在code:
INT HoleInstrumentenDiffListeDB(GTree *树)
{ OCI_Connection * CN;
OCI_Statement * ST;
OCI_Resultset * RS;
如果(!OCI_Initialize(err_handler,NULL,OCI_ENV_DEFAULT))
返回EXIT_FAILURE;
焦炭查询[500];
查询[0] ='\\ 0';
CN = OCI_ConnectionCreate(DB,U,P,OCI_SESSION_DEFAULT);
ST = OCI_StatementCreate(CN);
strcat的(查询,SELECT ...); OCI_ExecuteStmt(ST,查询);
RS = OCI_GetResultset(ST);
INT I = 1;
INT J = 0;
字符* symbolp;
而(OCI_FetchNext(RS)){
为const char * symbolp = OCI_GetString(RS,2);
开关(* OCI_GetString(RS,3))
{
案例'N':
insertQot(树,symbolp,OCI_GetInt(RS,1));
的printf(新\\ n);
打破;
案例'U':
insertQot(树,symbolp,OCI_GetInt(RS,1));
的printf(UPD \\ n);
打破;
案D:
deleteQot(树,symbolp);
的printf(德尔\\ n);
打破;
}
}
OCI_Cleanup();
返回1;
}诠释的main()
{ GTree * T = g_tree_new_full((GCompareDataFunc)g_ascii_strcasecmp,NULL,g_free,g_free);
HoleInstrumentenListe(T);
HoleInstrumentenDiffListeDB(T);
g_tree_destroy(T);
}
我觉得你应该释放 行中的
而()
循环,而不是在为()
循环的结束。我相信函数getline()
如果第一个参数是* NULL,所以你实际上是使用由第一个电话一遍遍分配的缓冲区将只分配内存。
但自从我写了很多C中,它是一个漫长的时间!
I'm compiling the code with -g flag and -O0. Please see valgrind output below.
I only want to know if I can I see what is invalid freed? I only see this:
==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
The code:
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);
}
I think you should be freeing line
inside the while ()
loop, not at the end of the for ()
loop. I believe getline()
will only allocate memory if the first parameter is *NULL, so you are in effect using the buffer allocated by the very first call over and over again.
But it's been a long while since I wrote much C!
这篇关于无效免费()/删除/在__libc_freeres删除[] / realloc的()()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!