From db736f83782261ad34b74a9cea4ef6f7f81d8fed Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Thu, 16 Sep 2010 19:33:18 +0000 Subject: [PATCH] Fix heap corruption svn path=/trunk/netsurf/; revision=10786 --- content/llcache.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/content/llcache.c b/content/llcache.c index de0c56b8f..37fd31e3c 100644 --- a/content/llcache.c +++ b/content/llcache.c @@ -158,7 +158,7 @@ static nserror llcache_object_retrieve_from_cache(const char *url, llcache_object **result); static bool llcache_object_is_fresh(const llcache_object *object); static nserror llcache_object_cache_update(llcache_object *object); -static nserror llcache_object_clone_cache_data(const llcache_object *source, +static nserror llcache_object_clone_cache_data(llcache_object *source, llcache_object *destination, bool deep); static nserror llcache_object_fetch(llcache_object *object, uint32_t flags, const char *referer, const llcache_post_data *post, @@ -845,8 +845,10 @@ nserror llcache_object_cache_update(llcache_object *object) * \param destination Destination object to clone cache data into * \param deep Whether to deep-copy the data or not * \return NSERROR_OK on success, appropriate error otherwise + * + * \post If \a deep is false, then any pointers in \a source will be set to NULL */ -nserror llcache_object_clone_cache_data(const llcache_object *source, +nserror llcache_object_clone_cache_data(llcache_object *source, llcache_object *destination, bool deep) { /* ETag must be first, as it can fail when deep cloning */ @@ -858,6 +860,9 @@ nserror llcache_object_clone_cache_data(const llcache_object *source, etag = strdup(source->cache.etag); if (etag == NULL) return NSERROR_NOMEM; + } else { + /* Destination takes ownership */ + source->cache.etag = NULL; } if (destination->cache.etag != NULL)