Skip to content

Commit

Permalink
Bugfix for PackJPG memory corruption
Browse files Browse the repository at this point in the history
- Double free in PackJPG's frealloc for the rare case of size == 0
- Fixes issue #17
  • Loading branch information
schnaader committed Jan 20, 2016
1 parent 78fa53e commit 120b3a0
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion contrib/packjpg/bitops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ reading and writing of arrays
// special realloc with guaranteed free() of previous memory
static inline void* frealloc( void* ptr, size_t size ) {
void* n_ptr = realloc( ptr, size );
if ( n_ptr == NULL ) free( ptr );
// changed by schnaader to fix a bug: if size == 0, realloc will free the memory and n_ptr == NULL, in this case don't call free
if (( n_ptr == NULL ) && (size != 0)) free( ptr );
return n_ptr;
}

Expand Down

0 comments on commit 120b3a0

Please sign in to comment.