fix crash due to bad allocation of indexing data space. First cut

used XP_REALLOC, but that turns out to be broken, at least on android.
Haven't really used it before...
This commit is contained in:
Andy2 2011-11-01 18:33:29 -07:00
parent 5827127ceb
commit 482aca5cfb

View file

@ -1316,18 +1316,18 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1destroy
{ {
DictIterData* data = (DictIterData*)closure; DictIterData* data = (DictIterData*)closure;
if ( NULL != data ) { if ( NULL != data ) {
dict_destroy( data->dict );
destroyJNIUtil( &data->jniutil );
if ( !!data->idata.indices ) {
XP_FREE( data->mpool, data->idata.indices );
}
if ( !!data->idata.prefixes ) {
XP_FREE( data->mpool, data->idata.prefixes );
}
vtmgr_destroy( MPPARM(data->mpool) data->vtMgr );
#ifdef MEM_DEBUG #ifdef MEM_DEBUG
MemPoolCtx* mpool = data->mpool; MemPoolCtx* mpool = data->mpool;
#endif #endif
dict_destroy( data->dict );
destroyJNIUtil( &data->jniutil );
if ( !!data->idata.indices ) {
XP_FREE( mpool, data->idata.indices );
}
if ( !!data->idata.prefixes ) {
XP_FREE( mpool, data->idata.prefixes );
}
vtmgr_destroy( MPPARM(mpool) data->vtMgr );
XP_FREE( mpool, data ); XP_FREE( mpool, data );
#ifdef MEM_DEBUG #ifdef MEM_DEBUG
mpool_destroy( mpool ); mpool_destroy( mpool );
@ -1354,24 +1354,46 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1iter_1makeIndex
DictIterData* data = (DictIterData*)closure; DictIterData* data = (DictIterData*)closure;
if ( NULL != data ) { if ( NULL != data ) {
data->depth = 2; /* for now */ data->depth = 2; /* for now */
DictPosition indices[32*32]; XP_U16 nFaces = dict_numTileFaces( data->dict );
Tile prefixes[data->depth*32*32]; XP_U16 ii;
IndexData idata = { .indices = indices, XP_U16 count;
.prefixes = prefixes, for ( count = 1, ii = 0; ii < data->depth; ++ii ) {
.count = VSIZE(indices) }; count *= nFaces;
}
dict_makeIndex( data->dict, data->depth, &idata ); IndexData* idata = &data->idata;
XP_ASSERT( !idata->prefixes );
idata->prefixes = XP_MALLOC( data->mpool, count * data->depth
* sizeof(*idata->prefixes) );
XP_ASSERT( !idata->indices );
idata->indices = XP_MALLOC( data->mpool,
count * sizeof(*idata->indices) );
idata->count = count;
dict_makeIndex( data->dict, data->depth, idata );
data->idata.indices = XP_MALLOC( data->mpool, Tile* tmp1 = idata->prefixes;
idata.count * idata->prefixes = XP_MALLOC( data->mpool,
sizeof(*data->idata.indices) ); idata->count * data->depth *
XP_MEMCPY( data->idata.indices, idata.indices, sizeof(*idata->prefixes) );
idata.count * sizeof(*data->idata.indices) ); XP_MEMCPY( idata->prefixes, tmp1, idata->count * data->depth *
data->idata.prefixes = XP_MALLOC( data->mpool, sizeof(*idata->prefixes) );
idata.count * data->depth * XP_FREE( data->mpool, tmp1 );
sizeof(*data->idata.indices) );
XP_MEMCPY( data->idata.prefixes, idata.prefixes, /* XP_REALLOC is broken, causes crashes when passed to XP_FREE in the
idata.count * data->depth * sizeof(*data->idata.prefixes) ); destructor below. Fix or remove. */
/* idata->prefixes = XP_REALLOC( data->mpool, idata->prefixes, */
/* idata->count * data->depth * */
/* sizeof(*idata->prefixes) ); */
DictPosition* tmp2 = idata->indices;
idata->indices = XP_MALLOC( data->mpool,
idata->count * sizeof(*idata->indices) );
XP_MEMCPY( idata->indices, tmp2,
idata->count * sizeof(*idata->indices) );
XP_FREE( data->mpool, tmp2 );
/* idata->indices = XP_REALLOC( data->mpool, idata->indices, */
/* idata->count * sizeof(*idata->indices) ); */
} }
} }