freeing allocated memory
From: Curley Q. (curleyq_at_bogus.net)
Date: 04/28/04
- Next message: Christopher Benson-Manica: "Re: freeing allocated memory"
- Previous message: Default User: "Re: main()"
- Next in thread: Christopher Benson-Manica: "Re: freeing allocated memory"
- Reply: Christopher Benson-Manica: "Re: freeing allocated memory"
- Reply: Christopher Benson-Manica: "Re: freeing allocated memory"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 28 Apr 2004 19:13:22 GMT
for(;;)
{
c = a * b;
c %= 100000;
printf("%9d", c);
d = int2str(c);
left = midstr(d, 0, 3);
right = midstr(d, strlen(d)-3, 3);
free(d);
a = atoi(left);
b = atoi(right);
if(a * b == 0)
break;
printf("%6d %6d\n", a, b);
}
free(left);
free(right);
In the code fragment above d is a buffer allocated by a call to
malloc in int2str and freed each pass through the loop. left and
right are also buffers allocated by calls to malloc in midstr,
but they are freed only once when execution breaks out of the
loop. What happens to the memory that is allocated to left and
right in each call to midstr? Is allocated memory getting cleaned
up properly in this code?
- Next message: Christopher Benson-Manica: "Re: freeing allocated memory"
- Previous message: Default User: "Re: main()"
- Next in thread: Christopher Benson-Manica: "Re: freeing allocated memory"
- Reply: Christopher Benson-Manica: "Re: freeing allocated memory"
- Reply: Christopher Benson-Manica: "Re: freeing allocated memory"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|