summaryrefslogtreecommitdiff
path: root/navit/cache.c
diff options
context:
space:
mode:
authorrikky <rikky@ffa7fe5e-494d-0410-b361-a75ebd5db220>2010-08-19 19:57:10 +0000
committerrikky <rikky@ffa7fe5e-494d-0410-b361-a75ebd5db220>2010-08-19 19:57:10 +0000
commit61d0daa33fa96694da404e43008ea96b3dd6a9c4 (patch)
tree874a2dd2e2429b08152f12832f5f70d4e6454bd6 /navit/cache.c
parent02a77ebcedcefe3d8b96f61aff217e4c62aabcb2 (diff)
downloadnavit-61d0daa33fa96694da404e43008ea96b3dd6a9c4.tar.gz
Fix:core:Fixed possible memory corruption in cache.c
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@3536 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit/cache.c')
-rw-r--r--navit/cache.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/navit/cache.c b/navit/cache.c
index b4aa9e0ae..3281e300f 100644
--- a/navit/cache.c
+++ b/navit/cache.c
@@ -216,10 +216,14 @@ cache_trim(struct cache *cache, struct cache_entry *entry)
struct cache_entry *new_entry;
if ( cache->entry_size < entry->size )
{
+ g_hash_table_remove(cache->hash, (gpointer)(entry->id));
+
new_entry = g_slice_alloc0(cache->entry_size);
memcpy(new_entry, entry, cache->entry_size);
g_slice_free1( entry->size, entry);
new_entry->size = cache->entry_size;
+
+ g_hash_table_insert(cache->hash, (gpointer)new_entry->id, new_entry);
}
else
{
@@ -233,12 +237,11 @@ static struct cache_entry *
cache_move(struct cache *cache, struct cache_entry_list *old, struct cache_entry_list *new)
{
struct cache_entry *entry;
- // remove from list AND cache, because next cache lookup can't read the id after trim
- entry=cache_remove_lru(cache, old);
+ entry=cache_remove_lru(NULL, old);
if (! entry)
return NULL;
entry=cache_trim(cache, entry);
- cache_insert_mru(cache, new, entry);
+ cache_insert_mru(NULL, new, entry);
return entry;
}