Re: Fix for memory corruption in yuvdeinterlace

Burkhard Plaum <[email protected]> Wed, 10 Oct 2007 19:46:17 +0200
Newsgroups gmane.comp.video.mjpeg.devel
Message-ID <[email protected]>
Hi,

Steven M. Schultz schrieb:
> 
> On Wed, 10 Oct 2007, Steven M. Schultz wrote:
> 
>> 	What _was_ happending was something like this:
>>
>> 	    a = malloc(num) + N;
>> 	    ...
>> 	    free(a-N);
> 
> 	Now before eveyone chimes in with "but of course that is correct"
> 	I'll mention that is only correct in this case
> 
> 	    for (i = N; i < num - N; i++)...
> 
> 	what was being done was effectively:
> 
> 	    for (i = N;  i < num ; i++)

No, what's done is:

a = malloc(num + 2*N) + N;

for(i = 0; i < num; i++)....

free(a - N);

this is correct, because it

- allows an overshoot by N in each direction
- passes exactly the pointer returned by malloc() to free()

Note that the variables luma_size and chroma_size already include the overshoot areas.

Burkhard

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/