File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed
archivelib-sys-orig/c-lib/src Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -722,9 +722,18 @@ int AL_PROTO ALMemory::Close()
722
722
mpcUserBuffer = (char AL_HUGE *) GlobalLock ( (HGLOBAL) mhUserMemoryHandle );
723
723
muUserBufferSize = mlSize;
724
724
#else
725
+ if (mlSize == 0 ) {
726
+ // 2019 -- Added this if/else block to prevent double free.
727
+ // Passing `0` into realloc will free the memory, then return
728
+ // null. This won't clear the reference to the buffer meaning
729
+ // ALMemory's deconstructor tries to free it again.
730
+ free (mpcUserBuffer);
731
+ mpcUserBuffer = NULL ;
732
+ } else {
725
733
char *new_buf = (char *) realloc ( mpcUserBuffer, (size_t ) mlSize );
726
734
if ( new_buf )
727
735
mpcUserBuffer = new_buf;
736
+ }
728
737
muUserBufferSize = (size_t ) mlSize;
729
738
#endif
730
739
}
You can’t perform that action at this time.
0 commit comments