Dynamic memory allocation in Audio library

I noticed this in arduino-1.5\hardware\arduino\sam\libraries\Audio\Audio.cpp

buffer = (uint32_t *) malloc(bufferSize * sizeof(uint32_t));

Does this use of malloc imply that Audio will have he same issues that the use of the String clas has at present? Or does the C compiler and library used on the SAM architecture not have those issues? (And if not, does that mean String is also safe to use, on Due?)

I didn't make deep tests about malloc to verify the fragmentation problem, so i don't know if we'll have the same String issues.
What i can say for sure is that in many months of tests i didn't had any issue with it.

In any case, Audio library does only one allocation at the moment of instantiation of the Audio object, so it should be safe even with a buggy malloc.
C

In any case, it isn't malloc() that is the problem in the AVR libs, it's free(). So if you malloc(), but never free(), there shouldn't be issues.

C, pico, thanks for the responses.

The Audio library does use free:

void AudioClass::end() {
	dac->end();
	free( buffer);
}

although it is not clear to me if that destructor is ever called, due to the setup+infinite-loop Arduino program structure.

Strictly speaking, this is not the destructor, but a method called "end", so you can call it explicitly using

audio.end();

in your sketch.