agent: Fix double free.
authorJustus Winter <justus@g10code.com>
Wed, 25 Jan 2017 12:51:57 +0000 (13:51 +0100)
committerJustus Winter <justus@g10code.com>
Wed, 25 Jan 2017 12:51:57 +0000 (13:51 +0100)
commite175152ef7515921635bf1e00383e812668d13fc
treebc2d9520a5bc0c3b9cef80bad8e8c677bab5b0be
parent5f2da5d439debf44615a97de788d8f720b517972
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>
agent/cache.c