diff --git a/tsk/img/img_writer.cpp b/tsk/img/img_writer.cpp index a55ee8165619f4590a56e012a16ce609f43911b9..2ec1ab322559d1d1fdbcb909f061e56fa1a17bf3 100644 --- a/tsk/img/img_writer.cpp +++ b/tsk/img/img_writer.cpp @@ -575,8 +575,15 @@ static TSK_RETVAL_ENUM tsk_img_writer_finish_image(TSK_IMG_WRITER* img_writer) { return TSK_ERR; } /* Using tsk_img_read here to make sure we get the lock */ - tsk_img_read(img_writer->img_info, offset, buffer, TSK_IMG_INFO_CACHE_LEN); + if (tsk_img_read(img_writer->img_info, offset, buffer, TSK_IMG_INFO_CACHE_LEN) < 0) { + // this usually happens when the device has been unplugged + return TSK_ERR; + } } + /* In Autopsy, tsk_img_writer_finish_image() was starving other threads that were trying to do + * basic reads and made the app impossible to use. Add the short sleep to give + * other threads a chance to get the underlying locks. */ + Sleep(1); } }