From 3d99626e8f889bbbcfa4cb1c72c51eda8c063e46 Mon Sep 17 00:00:00 2001 From: rikky Date: Tue, 7 Jun 2011 19:28:00 +0000 Subject: [PATCH] Fix:core:Fixed crashes after downloading map data git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@4515 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- navit/navit/file.c | 17 ++++++++++++++++- navit/navit/map/binfile/binfile.c | 15 ++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/navit/navit/file.c b/navit/navit/file.c index 8ed34ba..b87dbcf 100644 --- a/navit/navit/file.c +++ b/navit/navit/file.c @@ -653,13 +653,28 @@ file_data_free(struct file *file, unsigned char *data) return; if (data >= file->begin && data < file->end) return; - } + } if (file->cache && data) { cache_entry_destroy(file_cache, data); } else g_free(data); } +void +file_data_remove(struct file *file, unsigned char *data) +{ + if (file->begin) { + if (data == file->begin) + return; + if (data >= file->begin && data < file->end) + return; + } + if (file->cache && data) { + cache_flush_data(file_cache, data); + } else + g_free(data); +} + int file_exists(char const *name) { diff --git a/navit/navit/map/binfile/binfile.c b/navit/navit/map/binfile/binfile.c index d7c5bda..52bcccf 100644 --- a/navit/navit/map/binfile/binfile.c +++ b/navit/navit/map/binfile/binfile.c @@ -1042,14 +1042,14 @@ download_start(struct map_download *download) download->cd_copy=g_malloc(download->m->cde_size); memcpy(download->cd_copy, download->cd, download->m->cde_size); } - file_data_free(download->file, (unsigned char *)download->cd); + file_data_remove(download->file, (unsigned char *)download->cd); download->cd=NULL; offset=file_size(download->file); offset-=sizeof(struct zip_eoc); eoc=(struct zip_eoc *)file_data_read(download->file, offset, sizeof(struct zip_eoc)); download->zip_eoc=g_malloc(sizeof(struct zip_eoc)); memcpy(download->zip_eoc, eoc, sizeof(struct zip_eoc)); - file_data_free(download->file, (unsigned char *)eoc); + file_data_remove(download->file, (unsigned char *)eoc); download->start_offset=download->offset=offset; return download_request(download); } @@ -1090,21 +1090,22 @@ download_finish(struct map_download *download) struct zip_lfh *lfh; char *lfh_filename; struct zip_cd_ext *ext; - + long long lfh_offset; file_data_write(download->file, download->offset, sizeof(struct zip_eoc), (void *)download->zip_eoc); lfh=(struct zip_lfh *)(file_data_read(download->file,download->start_offset, sizeof(struct zip_lfh))); ext=binfile_cd_ext(download->cd_copy); - if (ext) + if (ext) ext->zipofst=download->start_offset; else download->cd_copy->zipofst=download->start_offset; download->cd_copy->zipcsiz=lfh->zipsize; download->cd_copy->zipcunc=lfh->zipuncmp; download->cd_copy->zipccrc=lfh->zipcrc; - lfh_filename=(char *)file_data_read(download->file,binfile_cd_offset(download->cd_copy)+sizeof(struct zip_lfh),lfh->zipfnln); + lfh_offset = binfile_cd_offset(download->cd_copy)+sizeof(struct zip_lfh); + lfh_filename=(char *)file_data_read(download->file,lfh_offset,lfh->zipfnln); memcpy(download->cd_copy+1,lfh_filename,lfh->zipfnln); - file_data_free(download->file,(void *)lfh_filename); - file_data_free(download->file,(void *)lfh); + file_data_remove(download->file,(void *)lfh_filename); + file_data_remove(download->file,(void *)lfh); file_data_write(download->file, download->m->eoc->zipeofst + download->zipfile*download->m->cde_size, binfile_cd_extra(download->cd_copy)+sizeof(struct zip_cd), (void *)download->cd_copy); file_data_flush(download->file, download->m->eoc->zipeofst + download->zipfile*download->m->cde_size, sizeof(struct zip_cd)); -- 2.7.4