Question

I have a strange problem, which I have not experienced till now.

I create two threads, and each thread basically opens a a FILE* to write some data onto the disk. Now, the writing part itself does not cause runtime problems (the output seems to be corrupted though), but all hell breaks loose when I close the two different FILE* in these two separate threads.

I see that one thread has _IO_buf_base pointing to 0x7ffff66d3000 whereas in the other thread _IO_write_end points to 0x7ffff66d3000. Maybe this is the reason that fclose thows up:

*** Error in `/home/raid/Documents/Temp/TemperatureMonitoringC/Debug/TemperatureMonitoringC': free(): invalid next size (normal): 0x00007ffff0000950 ***

*** Error in `/home/raid/Documents/Temp/TemperatureMonitoringC/Debug/TemperatureMonitoringC': free(): invalid next size (normal): 0x00007ffff0003540 ***

I am pretty sure that I am not the first person the have messed it up. Can anyone help? I could not find clear enough referenced on Google.

Debugger screenshots for both threads:

Debugger Window: Thread 1

Debugger Window: Thread 2

No correct solution

OTHER TIPS

I am back with a possible cause:

I had threads in which I was independently malloc'ing memory and then free'ing it. I read here that free should be in exact reverse order as that of malloc calls.

Since threads are basically asynchronous, and there was no way of really enforcing the malloc-free call order.

Of course, I would want to know whether malloc-free call order is required across the threads.

Can someone at least confirm whether I thinking correctly?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top