泄漏我有以下的代碼結構(完整的代碼是巨大的,我覺得這個片段是有關我的問題),Valgrind的報告,供mysql_real_connect
MYSQL_RES *res_set;
MYSQL_ROW row;
MYSQL *connect;
int main()
{
connect=mysql_init(NULL);
mysql_real_connect(connect, NULL, "root", "suvp" ,"Employees" ,0,NULL,0);
/*Other Code*/
mysql_free_result(res_set);
mysql_close(connect);
}
的變量數據庫連接是全球性的。在我的「其他代碼」中,我打電話給其他使用初始化connect
(在mysql_query
等)和row
和res_set
必要的功能。並且如我所見,我釋放結果並在主結束時關閉連接。
我再次使用res_set
(每次不釋放它)從一個函數到另一個函數。會導致問題嗎?
,不論我使用的功能,在staments類似
mysql_query(connect,myQuery.c_str())
res_set = mysql_store_result(connect);
row = mysql_fetch_row(res_set);
Valgrind的報告此,
==4864== LEAK SUMMARY:
==4864== definitely lost: 0 bytes in 0 blocks
==4864== indirectly lost: 0 bytes in 0 blocks
==4864== possibly lost: 0 bytes in 0 blocks
==4864== still reachable: 99,954 bytes in 30 blocks
==4864== suppressed: 0 bytes in 0 blocks
詳細的錯誤指出來
mysql_real_connect
從我的主叫功能。
根據此page調用mysql_library_end()
是很好的做法。但是,即使在關閉我的連接後,我打電話給mysql_library_end()
。 Valgrind的說,
==5120== HEAP SUMMARY:
==5120== in use at exit: 116,466 bytes in 34 blocks
==5120== total heap usage: 95 allocs, 61 frees, 147,218 bytes allocated
==5120== LEAK SUMMARY:
==5120== definitely lost: 0 bytes in 0 blocks
==5120== indirectly lost: 0 bytes in 0 blocks
==5120== possibly lost: 0 bytes in 0 blocks
==5120== still reachable: 116,466 bytes in 34 blocks
==5120== suppressed: 0 bytes in 0 blocks
而且正如早前,他們都歸結爲mysql_real_connect
程序運行正常。但是valgrind指出了一些問題。我哪裏錯了?
謝謝。這清除了一切。 –