This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Unexpected value-at for NULL'd pointer with pthreads
- From: Andrew Haley <aph at redhat dot com>
- To: Kyle Harper <kylejharper at gmail dot com>, Jonathan Wakely <jwakely dot gcc at gmail dot com>
- Cc: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Mon, 24 Aug 2015 16:15:00 +0100
- Subject: Re: Unexpected value-at for NULL'd pointer with pthreads
- Authentication-results: sourceware.org; auth=none
- References: <CAPcbWWxx3g9Uk9sn5jgG1GgmxSk1fjy5ybHKuRMzdKN3LJqt2Q at mail dot gmail dot com> <CAH8yC8nSNMGkbLWWcToBX6ZP5ygFFVqjKOmjq_pnvvFmfnxqSA at mail dot gmail dot com> <CAH6eHdSw84L3t9AqUjwGkvEU=4knZJvAod+d72OgusP0F5q0pA at mail dot gmail dot com> <CAPcbWWx-CQpJQvKHdHkObJ4wRv=9idRi1PaJuJ0nScMM7o6E_g at mail dot gmail dot com> <55DAD5B7 dot 90604 at redhat dot com> <CAPcbWWw8jv6kayXL-hZKOVhbMCQGoNNbT3e5j0hvYbPfPqfFBA at mail dot gmail dot com> <55DB2DED dot 20507 at redhat dot com> <CAH6eHdSgmfuia2A3a98nBGC5Gea-NMRQznEni20PgBVVQrONvA at mail dot gmail dot com> <CAPcbWWy-65PPiZVQ9PnYSeBNdO86HbMWqLK9cgU=CyPFzpKUuw at mail dot gmail dot com>
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.