[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnugo-devel] Memory leak analyse
From: |
pcibusgood |
Subject: |
[gnugo-devel] Memory leak analyse |
Date: |
Sun, 06 Mar 2005 17:46:56 +0800 |
bugs report:
Version:gnugo 3.7.2
OS:windows 98
Compiler:Visual C++ 6.0
Debug tool:NuMega BoundsChecker 6.5
Reporter name:QingYu Ma
Country:China
Memory leak analyse:
There is memory leak in the 773 lines of dragon.c.
" if (dragon2 != NULL)
free(dragon2);
dragon2 = malloc(number_of_dragons * sizeof(*dragon2));".
Because malloc() was executed more one time than free();
Details are given delow:
this function(static void initialize_supplementary_dragon_data(void)) was
called in the first time, free() didn't executed, while malloc() was executed;
this function was called in the second time, the memory that was requested in
the first time was freed by free(); go on and on, when this function was called
at last time, memory that was requested by malloc()was not freed.
In order to clarify this problem example program is given below:
#include <stdlib.h>
int *p = NULL;
void Exam1(void);
int main(int argc, char* argv[])
{
int i;
for(i=0; i<2; i++)
Exam1();
return 0;
}
void Exam1(void)
{
if(p != NULL)
free(p);
p = (int *)malloc(sizeof(int));
}
In this program, free() was executed one time, malloc() was executed two time,
memory leak four bytes(win98).
On the other hand, the prototype of malloc() is void *malloc(size_t size), I
think we should do forcible type change.
The standard use of malloc() is int *p = (int *)malloc(sizeof(int)*length).
Can you help me:
I want to known the way that two GnuGo play game each other in the Windows.
______________________________________
注册新浪免费邮箱,激活2G空间!( http://mail.sina.com.cn/chooseMode.html )
===================================================================
安全、易用、可靠 全新HP 商用笔记本经典上市 (http://ad4.sina.com.cn/wx/ads/hpzhuiyu228.html)
bug2.txt
Description: application/msdownload
- [gnugo-devel] Memory leak analyse,
pcibusgood <=