为什么加上 EXEC SQL ENABLE THREADS 后,就有内存泄漏呢?

[复制链接]
查看11 | 回复1 | 2013-2-25 14:51:24 | 显示全部楼层 |阅读模式
test.pc 源代码:
/*
* test.pc
*/
#include
#include
#include
#include

#include
#include

#define CONNINFO
"aaa/123"
EXEC ORACLE OPTION (ORACA=YES);

/* Handle SQL runtime errors. */
void sql_error(struct sqlca sqlca,char *msg)
{
/* This is the ORACLE error handler.
* Print diagnostic text containing error message,
* current SQL statement, and location of error.
*/
printf("\n%s", msg);
printf("\n%.*s\n",
sqlca.sqlerrm.sqlerrml, sqlca.sqlerrm.sqlerrmc);
printf("in \"%.*s...\"\n",
oraca.orastxt.orastxtl, oraca.orastxt.orastxtc);
printf("on line %d of %.*s.\n\n",
oraca.oraslnr, oraca.orasfnm.orasfnml,
oraca.orasfnm.orasfnmc);
/* Disable ORACLE error checking to avoid an infinite loop
* should another error occur within this routine.
*/
EXEC SQL WHENEVER SQLERROR CONTINUE;
/* Roll back any pending changes and
* disconnect from Oracle.
*/
EXEC SQL ROLLBACK RELEASE;
exit(EXIT_FAILURE);
}

/*
*
* logon
*/
void logon(sql_context ctx, char * connect_info)
//void logon(sql_context ctx)
{
EXEC SQL WHENEVER SQLERROR DO sql_error(sqlca, "Oracle error");
EXEC SQL CONTEXT USE :ctx;
EXEC SQL CONNECT :connect_info;
printf("Connected!\n");
}
/*
*
* logoff
*/
void logoff(sql_context ctx)
{
EXEC SQL WHENEVER SQLERROR DO sql_error(sqlca, "Oracle error");
EXEC SQL CONTEXT USE :ctx;
EXEC SQL COMMIT WORK RELEASE;
printf("Logged off!\n");
}
void main()
{

inti;

sql_context
arr[10];

EXEC SQL ENABLE THREADS;

EXEC SQL WHENEVER SQLERROR DO sql_error(sqlca, "Oracle error");


for(i=0;i复制代码
代码中有 EXEC SQL ENABLE THREADS; 时
[oracle@localhost]$ valgrind --tool=memcheck --leak-check=full ./test
... ...
==25475== LEAK SUMMARY:
==25475==definitely lost: 1,920 bytes in 10 blocks
// 内存泄漏
==25475==indirectly lost: 0 bytes in 0 blocks
==25475==possibly lost: 139,456 bytes in 2 blocks
==25475==still reachable: 759,246 bytes in 266 blocks
==25475== suppressed: 0 bytes in 0 blocks
==25475== Reachable blocks (those to which a pointer was found) are not shown.
==25475== To see them, rerun with: --leak-check=full --show-reachable=yes
... ...
把代码中的 EXEC SQL ENABLE THREADS; 屏蔽掉后就没有内存泄漏:
[oracle@localhost]$ valgrind --tool=memcheck --leak-check=full ./test
... ...
==25540==definitely lost: 0 bytes in 0 blocks
==25540==indirectly lost: 0 bytes in 0 blocks
==25540==possibly lost: 139,456 bytes in 2 blocks
==25540==still reachable: 755,662 bytes in 248 blocks
==25540== suppressed: 0 bytes in 0 blocks
==25540== Reachable blocks (those to which a pointer was found) are not shown.
==25540== To see them, rerun with: --leak-check=full --show-reachable=yes
... ...
为什么啊??? 高手帮忙啊~

回复

使用道具 举报

千问 | 2013-2-25 14:51:24 | 显示全部楼层
噢!是预编译时没加 THREADS=YES 的原因, 加上后就好了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行