libFLAC/md5.c: Clean up allocation
authorErik de Castro Lopo <erikd@mega-nerd.com>
Sat, 22 Aug 2015 21:37:53 +0000 (07:37 +1000)
committerErik de Castro Lopo <erikd@mega-nerd.com>
Sat, 22 Aug 2015 21:37:56 +0000 (07:37 +1000)
Make sure ctx->capacity gets updated correctly when safe_realloc()
fails.

Patch-from:  lvqcl <lvqcl.mail@gmail.com>

src/libFLAC/md5.c

index 05f824d..e9013a9 100644 (file)
@@ -499,13 +499,12 @@ FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const
                return false;
 
        if (ctx->capacity < bytes_needed) {
-               FLAC__byte *tmp = safe_realloc_(ctx->internal_buf.p8, bytes_needed);
-               if (0 == tmp) {
-                       if (0 == (ctx->internal_buf.p8 = safe_malloc_(bytes_needed)))
+               if (0 == (ctx->internal_buf.p8 = safe_realloc_(ctx->internal_buf.p8, bytes_needed))) {
+                       if (0 == (ctx->internal_buf.p8 = safe_malloc_(bytes_needed))) {
+                               ctx->capacity = 0;
                                return false;
+                       }
                }
-               else
-                       ctx->internal_buf.p8 = tmp;
                ctx->capacity = bytes_needed;
        }