This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Unexpected value-at for NULL'd pointer with pthreads


On 08/24/2015 04:06 PM, Kyle Harper wrote:
> I understand that double-free()ing is a fatal access violate, however
> this shouldn't be happening in the first place.  I am using pthread
> primitives (mutexes) to guard the critical section wherein I first
> free, then set to NULL the pointer that both threads are looking at.
> The first thread to reach the critical section should (and does)
> free() and NULL, then asserts that *buf == NULL.  The second thread to
> reach the critical section should return without performing any action
> because of the if(*buf == NULL).... section, but it doesn't.

No, you're not.  In the example you just posted only one buffer
is ever allocated and you free it twice.

Andrew.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]