in reply to Perl XS: garbage-collecting my malloc'd buffer
Not about Perl, but for the c code, it is better to check whether tmp_buffer is NULL, after the malloc call. If it is NULL, then the malloc failed, and there is no point to continue, otherwise you would see core dumps somewhere down the road. It is also better to check whether it is a NULL pointer, before you free it.
(As this is demo, I guess you might have the checking in your real code ;-), just in case…)