我使用Valgrind在memcheck進程期間編寫了兩段如下所示的c程序,給出了很多mem泄漏信息。可能的內存泄漏問題
int
GetMemory(int framewidth,
int frameheight,
int SR/*, int blocksize*//*,int ALL_REF_NUM*/)
{
//int i,j;
int memory_size = 0;
//int refnum = ALL_REF_NUM;
int input_search_range = SR;
memory_size += get_mem2D(&curFrameY, frameheight, framewidth);
memory_size += get_mem2D(&curFrameU, frameheight>>1, framewidth>>1);
memory_size += get_mem2D(&curFrameV, frameheight>>1, framewidth>>1);
memory_size += get_mem3D(&prevFrameY, refnum, frameheight, framewidth);// to allocate reference frame buffer accoding to the reference frame number
memory_size += get_mem3D(&prevFrameU, refnum, frameheight>>1, framewidth>>1);
memory_size += get_mem3D(&prevFrameV, refnum, frameheight>>1, framewidth>>1);
memory_size += get_mem2D(&mpFrameY, frameheight, framewidth);
memory_size += get_mem2D(&mpFrameU, frameheight>>1, framewidth>>1);
memory_size += get_mem2D(&mpFrameV, frameheight>>1, framewidth>>1);
memory_size += get_mem2D(&searchwindow, input_search_range*2 + blocksize, input_search_range*2 + blocksize);// to allocate search window according to the searchrange
/*memory_size +=*/ get_mem1D(/*&SAD_cost, height, width*/);
// memory_size += get_mem2D(&searchwindow, 80, 80);// if searchrange is 32, then only 32+1+32+15 pixels is needed in each row and col, therefore the range of
// search window is enough to be set to 80 !
memory_size += get_mem2Dint(&all_mv, height/blocksize, width/blocksize);
return 0;
}
void
FreeMemory(int refno)
{
free_mem2D(curFrameY);
free_mem2D(curFrameU);
free_mem2D(curFrameV);
free_mem3D(prevFrameY,refno);
free_mem3D(prevFrameU,refno);
free_mem3D(prevFrameV,refno);
free_mem2D(mpFrameY);
free_mem2D(mpFrameU);
free_mem2D(mpFrameV);
free_mem2D(searchwindow);
free_mem1D();
free_mem2Dint(all_mv);
}
void free_mem1D()
{
free(SAD_cost);
}
現在我希望,以確保地方都在我的計劃中可能出現的問題? 在這裏,我可能會發布一些valgrind信息,讓你知道實際的錯誤信息。
== 29105 ==由0x804A906:主(me_search.c:1480)
== 29105 ==
== 29105 ==
== 29105 == HEAP內容:
== 29105 ==在使用中在出口處:在18個塊
== 29105 ==總堆使用124088個字節:37個allocs,21周的FreeS,749276個字節分配
== 29105 ==
== 29105 ==在1塊272個字節仍然在損失記錄29105 ==在0x402425F 18 1的
==可達:釋放calloc(vg_replace_malloc.c: 467)
== 29105 ==由0x804A296:get_mem2D(me_search.c:1315)
== 29105 ==由0x804885E:GetMemory(me_search.c:117)
== 29105 = = by 0x804A757:main(me_search.c:1 456)
== 29105 ==
== 29105 ==在1塊352個字節仍然在損失記錄2 18的
== 29105 ==在0x4024F20可達:malloc的(vg_replace_malloc。 C:236)
== 29105 ==由0x409537E:__fopen_internal(iofopen.c:76)
== 29105 ==由0x409544B:的fopen @@ GLIBC_2.1(iofopen.c:107)
== 29105 =通過= 0x804A660:主(me_search.c:1439)
== 29105 ==
== 29105 ==在1塊584個字節仍然在損失記錄3 18
可達== 29105 ==在0x402425F:釋放calloc(vg_replace_malloc.c:467)
== 29105 ==由0x804A296:get_mem2D(me_search.c:1315)
== 29105 ==由0x8048724:GetMemory(me_search。 c:106)
== 29105 == by 0x804A757:main(me_search。C:1456)
== 29105 ==
== 29105 ==在1塊584個字節仍然在損失記錄4 18
==在0x402425F 29105 ==可達:釋放calloc( vg_replace_malloc.c:467)
== 29105 ==由0x804A296:get_mem2D(me_search.c:1315)
== 29105 ==由0x8048747:GetMemory(me_search.c:107)
== 29105 ==由0x804A757:主(me_search.c:1456)
== 29105 ==
== 29105 ==在1塊584個字節仍然在損失記錄18 == 29105 5的
可達= =上0x402425F:釋放calloc(vg_replace_malloc.c:467)
== 29105 ==由0x804A296:get_mem2D(me_search.c:1315)
== 29105 ==由0x8048809:GetMemory(me_search.c: 114)
== 29105 ==由0x804A757:主(me_search.c:1456)
== 29105 ==
== 29105 ==在1塊584個字節仍然在損失記錄18
6的可達== 29105 ==在0x402425F:釋放calloc(vg_replace_malloc.c:467)
== 29105 ==由0x804A296:get_mem2D(me_search.c:1315)
== 29105 ==通過0x804882C :GetMemory(me_search.c:115)
== 29105 ==由0x804A757:主(me_search.c:1456)
== 29105 ==
== 29105 ==在1塊584個字節中記錄損失18 7的肯定丟失
== 29105 ==在0x402425F:釋放calloc(vg_replace_malloc.c:467)
== 29105 ==由0x804A296:get_mem2D(me_search.c:1315)
== 29105 ==由0x804A4F8:get_mem3D(me_search.c:1393)
== 29105 ==由0x804879B:GetMemory(me_search.c:110)
== 29105 ==由0x804A757:主(me_search.c:1456)
== 29105 ==
== 29105 ==在1塊584個字節中記錄損失8 18
==在0x402425F 29105 ==肯定丟失:釋放calloc(vg_replace_malloc.c:467)
== 29105 ==由0x804A296:get_mem2D(me_search。C:1315)
== 29105 ==由0x804A4F8:get_mem3D(me_search.c:1393)
== 29105 ==由0x80487C9:GetMemory(me_search.c:111)
== 29105 ==通過0x804A757:主(me_search.c:1456)
== 29105 ==
== 29105 ==在1塊1168個字節仍然在9的損失記錄可達18
== 29105 ==在0x40242 5F:釋放calloc(vg_replace_malloc.c:467)
== 29105 ==由0x804A296:get_mem2D(me_search.c:1315)
== 29105 ==由0x8048701:GetMemory(me_search.c:105)
== 29105 ==由0x804A757:主(me_search.c:1456)
== 29105 ==
== 29105 ==在1塊1168個字節仍然在損失記錄10可到達的的18
== 29105 ==在0x402425F:釋放calloc(vg_replace_malloc.c:467)
== 29105 ==由0x804A296:get_mem2D(me_search.c:1315)
== 29105 ==由0x80487E6:GetMemory (me_search.c:113)
== 29105 ==由0x804A757:主(me_search.c:1456)
== 29105 ==
== 29105 ==在1塊1168個字節肯定輸了18場失利紀錄11
== 29105 ==在0x402425F:釋放calloc(vg_replace_malloc.c:467)
== 29105 ==由0x804A296:get_mem2D(me_search.c:1315)
== 29105 ==由0x804A4F8: get_mem3D(me_search.c:1393)
== 29105 ==由0x804876D:GetMemory(me_search.c:109)
== 29105 ==由0x804A757:主(me_search.c:1456)
== 29105 ==
== 29105 ==在1塊6336個字節中記錄損失18 12
==在0x4024F20 29105 ==肯定丟失:malloc的(vg_replace_malloc.c:236)
== 29105 ==通過0x804A25C:get_mem1D(me_search.c:1295)
== 29105 ==由0x8048866:GetMemory(me_search.c:119)
== 29105 ==由0x804A757:主(me_search。C:1456)
是什麼讓你覺得有內存泄漏?你有什麼試圖找到它?你想達到什麼目的?這個代碼*應該做什麼?請添加更多信息以幫助那些試圖幫助您的人。 – DevinB 2010-06-07 09:14:55
因爲我發現我無法在linux環境下在我的Firefox瀏覽器中編輯帖子。因此,我首先通過該程序,然後轉到另一臺計算機編輯此帖。 對不起,造成的不便。 – MaiTiano 2010-06-07 09:18:12
您是否驗證過FreeMemory是否被卡住? – DevinB 2010-06-07 09:22:38