diff options
author | rikky <rikky@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2011-06-07 19:28:00 +0000 |
---|---|---|
committer | rikky <rikky@ffa7fe5e-494d-0410-b361-a75ebd5db220> | 2011-06-07 19:28:00 +0000 |
commit | 94b7ddf91f3bc0205326dad49ec9abfa41cecf3e (patch) | |
tree | 7bea63ce1f652a94f155cdb6cc3c14ffa03010ad /navit | |
parent | 56fef9d2bf77afa909bd756e7cd38d83cf966c8d (diff) | |
download | navit-94b7ddf91f3bc0205326dad49ec9abfa41cecf3e.tar.gz |
Fix:core:Fixed crashes after downloading map data
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@4515 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit')
-rw-r--r-- | navit/file.c | 17 | ||||
-rw-r--r-- | navit/map/binfile/binfile.c | 15 |
2 files changed, 24 insertions, 8 deletions
diff --git a/navit/file.c b/navit/file.c index 8ed34baa2..b87dbcf88 100644 --- a/navit/file.c +++ b/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/map/binfile/binfile.c b/navit/map/binfile/binfile.c index d7c5bda82..52bcccf5b 100644 --- a/navit/map/binfile/binfile.c +++ b/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)); |