SigSegv's in AudioSampleBuffer::allocate


#1

I’m crashing in here when a bug in my program causes me to allocate way too many buffers.

The problem seems to be where the data is allocated and then chan += size; accesses invalid memory.

Obviously I shouldn’t use up so much memory, and should hit my bug, but even with some super heavy throwing around of video, this seems to be the first failure.

Is it reasonable to check the pointer and have a blank buffer? Throw an exception?

Bruce

[code]void AudioSampleBuffer::allocateData()
{
const size_t channelListSize = (numChannels + 1) * sizeof (float*);
allocatedBytes = (int) (numChannels * size * sizeof (float) + channelListSize + 32);
allocatedData.malloc (allocatedBytes);
channels = reinterpret_cast <float**> (allocatedData.getData());

float* chan = (float*) (allocatedData + channelListSize);
for (int i = 0; i < numChannels; ++i)
{
    channels[i] = chan;
    chan += size;
}

channels [numChannels] = 0;

}
[/code]


#2

When the day comes when I start adding exceptions in the library, I’ll certainly make things like HeapBlock throw in that kind of situation.

…but if you’re just allocating huge amounts of memory because of an arithmetic blooper, wouldn’t it be better to sanity-check the numbers before passing them to the buffer?


#3

I don’t think it’s an arithmetic snafu, I thought it was the sheer number of buffers I make when they aren’t being consumed properly (fighting with timestamps in a producer/consumer situation).

I wonder… the one time I caught it in a debugger, it seemed that the amount being allocated was actually really small, like 132. What could be happening is it may be a new buffer, and I’m asking for some minor amount of memory, like 25 samples x 2 channels x 16-bit = 100, plus the 32 byte pad it looks like the buffer needs. (Not an error btw, just some bytes left at the end of a file probably)

Could the channel access be running off the end somehow? Is there a minimum size? I see the buffer adding it’s own padding, are there any situations where it’s not enough? That makes more sense than the whole machine running out of memory.

Bruce


#4

There shouldn’t be any problem allocating them if they’re sensible sizes and your machine still has memory free… Could you be hitting something like a 2GB 32-bit address space limit?