[Libav-user] g++ 4.7.2 fails to compile av_err2str

"René J.V. Bertin" rjvbertin at gmail.com
Mon Jan 14 18:04:52 CET 2013


On Jan 14, 2013, at 17:49, Nicolas George wrote:
>> 				But Microsoft compiler only recognizes
>> _alloca().
> 
> There you are.

#ifdef _MSC_VER
#	define alloca(n)	_alloca(n)
#endif

> 
> There is another problem with alloca(): the scope of the allocation is
> per function, while the scope of a compound literal, as used by the macro
> currently, is per block.

Are you sure? I was under the impression that

n = 10;
{ char *foo = (char*) alloca(n); // char foo[n] in gcc :)
	// fill foo
	printf( "%s\n", foo );
}

is equivalent to

{ char foo[10];
	// fill foo
	printf( "%s\n", foo );
}

meaning that the stack-deallocation of *foo happens upon exit from the block, like the releasing of foo[10] ...

> with the current macro, works as expected, whereas if the macro were based
> on alloca(), the error strings would stay allocated until the loop is
> completed. That is a memory leak. Probably not terrible, but still a leak.
 
In my book, a memory leak is memory that's allocated but never deallocated. That's not the case here... it's more like a caching/garbage-collection scheme. And as long as there are few errors being reported, there won't be much memory to free.

R.


More information about the Libav-user mailing list