Opened 14 years ago
Closed 14 years ago
#330 closed defect/bug (fixed)
Out of memory error while allocating memory on the stack
Reported by: | Zittix | Owned by: | KaZeR |
---|---|---|---|
Priority: | minor | Milestone: | |
Component: | core | Version: | git master |
Severity: | Keywords: | ||
Cc: |
Description
While porting Navit on the iPhone I found a problem in the file_data_read_compressed() function. The buffer var. is allocated on the stack instead on the heap and sometimes it requires more than 1 Mb to be allocated.
Here is the fixed version:
unsigned char * file_data_read_compressed(struct file *file, long long offset, int size, int size_uncomp) {
void *ret; char *buffer=0;
uLongf destLen=size_uncomp; if (file_cache) {
struct file_cache_id id={offset,size,file->name_id,1}; ret=cache_lookup(file_cache,&id); if (ret)
return ret;
ret=cache_insert_new(file_cache,&id,size_uncomp);
} else {
ret=g_malloc(size_uncomp);
} lseek(file->fd, offset, SEEK_SET); buffer=g_malloc(size); if (read(file->fd, buffer, size) != size) {
g_free(ret); ret=NULL;
} else {
if (uncompress_int(ret, &destLen, (Bytef *)buffer, size) != Z_OK) {
dbg(0,"uncompress failed\n"); g_free(ret); ret=NULL;
}
} g_free(buffer); return ret;
}
Change History (1)
comment:1 Changed 14 years ago by Tinloaf
- Resolution set to fixed
- Status changed from new to closed
This has been applied in revision 2187. Thanks for the patch!