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>
Mon, 18 Sep 2017 20:41:12 +0000 (21:41 +0100)
commit26130564098c3748d9aa5fa0e5734226cfca787a
tree0bc7595f1dfcea26f583c8f76c6ec5e553a00597
parentb236328cca0d116a22ff4332e206a8419a0aa32f
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