chiark / gitweb /
agent: Fix double free.
authorJustus Winter <justus@g10code.com>
Wed, 25 Jan 2017 12:51:57 +0000 (13:51 +0100)
committerDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Tue, 14 Feb 2017 00:29:34 +0000 (00:29 +0000)
commit41b9c2c928bbee68843a76bb465b68b3daa3e57d
treea1b2005c3b5b0287c33f026f08baa9663e2bb23b
parentf5f34ae0b5a8a7cb0fd4f7bb8271841a3da29cc9
agent: Fix double free.

* agent/cache.c (agent_store_cache_hit): Make sure the update is
atomic.
--
Previously, the function freed the last key, and duplicated the new
key after doing that.  There is a chance, however, that calling the
allocator surrenders control to a different thread, causing a double
free if a different thread also calls this function.

To make sure the update is atomic under the non-preemptive thread
model, we must make sure not to surrender control to a different
thread.  Therefore, we avoid calling the allocator during the
update.

Signed-off-by: Justus Winter <justus@g10code.com>
(cherry picked from commit e175152ef7515921635bf1e00383e812668d13fc)

Gbp-Pq: Name 0017-agent-Fix-double-free.patch
agent/cache.c