It seems that the SIGALRM masking is swapped in the code. The attached patch seems to solve the problem (at least for me :). I have tried this solution at first but it didn't work. Maybe that my added debug code interfere with original code, may be it was too late or the problem may be deeper. Now the patched code works for two days without problem but I will also do more testing
Sorry for the delay in response. Your patch seems correct to me. I had seen that code before and wondered why it worked :) I have tested it here (linux/slackware) with a variety of short and long samples and do not see any problems so far.