From: Clemens L. <cl...@la...> - 2011-05-05 06:26:23
|
Alaney Dória wrote: > *** Program received signal SIGABRT (Aborted) *** > *** glibc detected *** /home/alien/Projects/ffado-2/tests/ffado-test: free(): invalid next size (fast): 0x00000000006394e0 *** > /usr/lib/libffado.so.2(_ZNK9ConfigRom13getGuidStringEv+0x88)[0x7ffff7c071ce] > > at the start I thought it was problem with addElement but after further > debugging I found that is free that is making the SIGABRT. It's not > missing a malloc in the following code? No, free() is correct for asprintf(). > const std::string > ConfigRom::getGuidString() const > { > char* buf; > asprintf( &buf, "%08x%08x", > ( unsigned int ) ( getGuid() >> 32 ), > ( unsigned int ) ( getGuid() & 0xffffffff ) ); In theory, you should check the return value, because buf is undefined after an error, but in practice, running out of memory is very unlikely. > std::string result = buf; > free( buf ); > return result; > } This code looks correct. It's possible that some previous code corrupted memory and that this call to free() is just the first that notices it. Anyway, the size of the string is known, so you could avoid the memory allocation by using "char buf[17]". Whether this would move the crash to another free() call is another question ... Regards, Clemens |