diff --git a/NEWS.txt b/NEWS.txt index b77ddd56f21fc114d928f5e3c7c1c828f55a69ab..e13b231abafd3c3369fcaf267cfdfc37ec4b6738 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -18,6 +18,7 @@ applied to deleted directories. New Features: - 3213888: RAW CD format - Auto class accepts TSK_IMG_INFO as argument +- Copies of split image file names are stored in TSK so that the caller can free them before TSK_IMG_INFO is freed. ---------------- VERSION 3.2.1 -------------- Bug Fixes diff --git a/tsk3/img/split.c b/tsk3/img/split.c index cfb74ad3e83f5406e2f8a2a6891d40707d5714f9..a3af4b6408b9ed5654ef43fe48f2197d768540c5 100644 --- a/tsk3/img/split.c +++ b/tsk3/img/split.c @@ -317,8 +317,16 @@ split_close(TSK_IMG_INFO * img_info) close(split_info->cache[i].fd); #endif } - free(split_info->max_off); - free(split_info->cptr); + for(i = 0; i < split_info->num_img; i++){ + if (split_info->images[i]) + free(split_info->images[i]); + } + if (split_info->max_off) + free(split_info->max_off); + if (split_info->images) + free(split_info->images); + if (split_info->cptr) + free(split_info->cptr); free(split_info); } @@ -376,9 +384,32 @@ split_open(int num_img, const TSK_TCHAR * const images[], return NULL; } img_info->size = 0; - + split_info->num_img = num_img; - split_info->images = images; + + split_info->images = (TSK_TCHAR **) tsk_malloc(sizeof(TSK_TCHAR *) * num_img); + if(split_info->images == NULL){ + free(split_info->max_off); + free(split_info->cptr); + free(split_info); + return NULL; + } + for(i=0; i < num_img; i++){ + size_t len = TSTRLEN(images[i]); + split_info->images[i] = (TSK_TCHAR *) tsk_malloc(sizeof(TSK_TCHAR) * (len+1)); + if(split_info->images == NULL){ + while(i > 0){ + i--; + free(split_info->images[i]); + } + free(split_info->images); + free(split_info->max_off); + free(split_info->cptr); + free(split_info); + return NULL; + } + TSTRNCPY(split_info->images[i], images[i], len); + } /* Get size info for each file - we do not open each one because that * could cause us to run out of file decsriptors when we only need a few. diff --git a/tsk3/img/split.h b/tsk3/img/split.h index cad90dad42e779af9d9ee18914815137c3f24cc0..e3cde68a92af18211230ce0ebcdd3283b2041124 100644 --- a/tsk3/img/split.h +++ b/tsk3/img/split.h @@ -38,7 +38,7 @@ extern "C" { int num_img; // the following are protected by cache_lock in IMG_INFO - const TSK_TCHAR *const *images; + TSK_TCHAR **images; TSK_OFF_T *max_off; int *cptr; /* exists for each image - points to entry in cache */ IMG_SPLIT_CACHE cache[SPLIT_CACHE]; /* small number of fds for open images */