libavformat/matroskadec.c:967: error: Memory Leak
  memory dynamically allocated by call to `av_realloc()` at line 967, column 24 is not reachable after line 967, column 13.

libavformat/matroskadec.c:931:1: start of procedure matroska_decode_buffer()
929. }
930. 
931. static int matroska_decode_buffer(uint8_t** buf, int* buf_size,
     ^
932.                                   MatroskaTrack *track)
933. {

libavformat/matroskadec.c:934:5: 
932.                                   MatroskaTrack *track)
933. {
934.     MatroskaTrackEncoding *encodings = track->encodings.elem;
         ^
935.     uint8_t* data = *buf;
936.     int isize = *buf_size;

libavformat/matroskadec.c:935:5: 
933. {
934.     MatroskaTrackEncoding *encodings = track->encodings.elem;
935.     uint8_t* data = *buf;
         ^
936.     int isize = *buf_size;
937.     uint8_t* pkt_data = NULL;

libavformat/matroskadec.c:936:5: 
934.     MatroskaTrackEncoding *encodings = track->encodings.elem;
935.     uint8_t* data = *buf;
936.     int isize = *buf_size;
         ^
937.     uint8_t* pkt_data = NULL;
938.     int pkt_size = isize;

libavformat/matroskadec.c:937:5: 
935.     uint8_t* data = *buf;
936.     int isize = *buf_size;
937.     uint8_t* pkt_data = NULL;
         ^
938.     int pkt_size = isize;
939.     int result = 0;

libavformat/matroskadec.c:938:5: 
936.     int isize = *buf_size;
937.     uint8_t* pkt_data = NULL;
938.     int pkt_size = isize;
         ^
939.     int result = 0;
940.     int olen;

libavformat/matroskadec.c:939:5: 
937.     uint8_t* pkt_data = NULL;
938.     int pkt_size = isize;
939.     int result = 0;
         ^
940.     int olen;
941. 

libavformat/matroskadec.c:942:9: Taking false branch
940.     int olen;
941. 
942.     if (pkt_size >= 10000000)
             ^
943.         return -1;
944. 

libavformat/matroskadec.c:945:5: 
943.         return -1;
944. 
945.     switch (encodings[0].compression.algo) {
         ^
946.     case MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP:
947.         return encodings[0].compression.settings.size;

libavformat/matroskadec.c:946:5: Switch condition is false. Skipping switch case
944. 
945.     switch (encodings[0].compression.algo) {
946.     case MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP:
         ^
947.         return encodings[0].compression.settings.size;
948.     case MATROSKA_TRACK_ENCODING_COMP_LZO:

libavformat/matroskadec.c:948:5: Switch condition is false. Skipping switch case
946.     case MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP:
947.         return encodings[0].compression.settings.size;
948.     case MATROSKA_TRACK_ENCODING_COMP_LZO:
         ^
949.         do {
950.             olen = pkt_size *= 3;

libavformat/matroskadec.c:959:5: Switch condition is true. Entering switch case
957.         break;
958. #if CONFIG_ZLIB
959.     case MATROSKA_TRACK_ENCODING_COMP_ZLIB: {
         ^
960.         z_stream zstream = {0};
961.         if (inflateInit(&zstream) != Z_OK)

libavformat/matroskadec.c:960:9: 
958. #if CONFIG_ZLIB
959.     case MATROSKA_TRACK_ENCODING_COMP_ZLIB: {
960.         z_stream zstream = {0};
             ^
961.         if (inflateInit(&zstream) != Z_OK)
962.             return -1;

libavformat/matroskadec.c:961:13: Taking false branch
959.     case MATROSKA_TRACK_ENCODING_COMP_ZLIB: {
960.         z_stream zstream = {0};
961.         if (inflateInit(&zstream) != Z_OK)
                 ^
962.             return -1;
963.         zstream.next_in = data;

libavformat/matroskadec.c:963:9: 
961.         if (inflateInit(&zstream) != Z_OK)
962.             return -1;
963.         zstream.next_in = data;
             ^
964.         zstream.avail_in = isize;
965.         do {

libavformat/matroskadec.c:964:9: 
962.             return -1;
963.         zstream.next_in = data;
964.         zstream.avail_in = isize;
             ^
965.         do {
966.             pkt_size *= 3;

libavformat/matroskadec.c:966:13: 
964.         zstream.avail_in = isize;
965.         do {
966.             pkt_size *= 3;
                 ^
967.             pkt_data = av_realloc(pkt_data, pkt_size);
968.             zstream.avail_out = pkt_size - zstream.total_out;

libavformat/matroskadec.c:967:13: 
965.         do {
966.             pkt_size *= 3;
967.             pkt_data = av_realloc(pkt_data, pkt_size);
                 ^
968.             zstream.avail_out = pkt_size - zstream.total_out;
969.             zstream.next_out = pkt_data + zstream.total_out;

libavutil/mem.c:117:1: start of procedure av_realloc()
  115. }
  116. 
  117. void *av_realloc(void *ptr, size_t size)
       ^
  118. {
  119. #if CONFIG_MEMALIGN_HACK

libavutil/mem.c:124:8: Taking false branch
  122. 
  123.     /* let's disallow possible ambiguous cases */
  124.     if(size > (INT_MAX-16) )
              ^
  125.         return NULL;
  126. 

libavutil/mem.c:133:5: 
  131.     return (char*)realloc((char*)ptr - diff, size + diff) + diff;
  132. #else
  133.     return realloc(ptr, size);
           ^
  134. #endif
  135. }

libavutil/mem.c:135:1: return from a call to av_realloc
  133.     return realloc(ptr, size);
  134. #endif
  135. }
       ^
  136. 
  137. void av_free(void *ptr)

libavformat/matroskadec.c:968:13: 
966.             pkt_size *= 3;
967.             pkt_data = av_realloc(pkt_data, pkt_size);
968.             zstream.avail_out = pkt_size - zstream.total_out;
                 ^
969.             zstream.next_out = pkt_data + zstream.total_out;
970.             result = inflate(&zstream, Z_NO_FLUSH);

libavformat/matroskadec.c:969:13: 
967.             pkt_data = av_realloc(pkt_data, pkt_size);
968.             zstream.avail_out = pkt_size - zstream.total_out;
969.             zstream.next_out = pkt_data + zstream.total_out;
                 ^
970.             result = inflate(&zstream, Z_NO_FLUSH);
971.         } while (result==Z_OK && pkt_size<10000000);

libavformat/matroskadec.c:970:13: Skipping inflate(): method has no implementation
968.             zstream.avail_out = pkt_size - zstream.total_out;
969.             zstream.next_out = pkt_data + zstream.total_out;
970.             result = inflate(&zstream, Z_NO_FLUSH);
                 ^
971.         } while (result==Z_OK && pkt_size<10000000);
972.         pkt_size = zstream.total_out;

libavformat/matroskadec.c:971:18: Loop condition is true. Entering loop body
969.             zstream.next_out = pkt_data + zstream.total_out;
970.             result = inflate(&zstream, Z_NO_FLUSH);
971.         } while (result==Z_OK && pkt_size<10000000);
                      ^
972.         pkt_size = zstream.total_out;
973.         inflateEnd(&zstream);

libavformat/matroskadec.c:971:34: Loop condition is true. Entering loop body
969.             zstream.next_out = pkt_data + zstream.total_out;
970.             result = inflate(&zstream, Z_NO_FLUSH);
971.         } while (result==Z_OK && pkt_size<10000000);
                                      ^
972.         pkt_size = zstream.total_out;
973.         inflateEnd(&zstream);

libavformat/matroskadec.c:966:13: 
964.         zstream.avail_in = isize;
965.         do {
966.             pkt_size *= 3;
                 ^
967.             pkt_data = av_realloc(pkt_data, pkt_size);
968.             zstream.avail_out = pkt_size - zstream.total_out;

libavformat/matroskadec.c:967:13: 
965.         do {
966.             pkt_size *= 3;
967.             pkt_data = av_realloc(pkt_data, pkt_size);
                 ^
968.             zstream.avail_out = pkt_size - zstream.total_out;
969.             zstream.next_out = pkt_data + zstream.total_out;

libavutil/mem.c:117:1: start of procedure av_realloc()
  115. }
  116. 
  117. void *av_realloc(void *ptr, size_t size)
       ^
  118. {
  119. #if CONFIG_MEMALIGN_HACK

libavutil/mem.c:124:8: Taking true branch
  122. 
  123.     /* let's disallow possible ambiguous cases */
  124.     if(size > (INT_MAX-16) )
              ^
  125.         return NULL;
  126. 

libavutil/mem.c:125:9: 
  123.     /* let's disallow possible ambiguous cases */
  124.     if(size > (INT_MAX-16) )
  125.         return NULL;
               ^
  126. 
  127. #if CONFIG_MEMALIGN_HACK

libavutil/mem.c:135:1: return from a call to av_realloc
  133.     return realloc(ptr, size);
  134. #endif
  135. }
       ^
  136. 
  137. void av_free(void *ptr)

static int matroska_decode_buffer(uint8_t** buf, int* buf_size,
                                  MatroskaTrack *track)
{
    MatroskaTrackEncoding *encodings = track->encodings.elem;
    uint8_t* data = *buf;
    int isize = *buf_size;
    uint8_t* pkt_data = NULL;
    int pkt_size = isize;
    int result = 0;
    int olen;
    if (pkt_size >= 10000000)
        return -1;
    switch (encodings[0].compression.algo) {
    case MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP:
        return encodings[0].compression.settings.size;
    case MATROSKA_TRACK_ENCODING_COMP_LZO:
        do {
            olen = pkt_size *= 3;
            pkt_data = av_realloc(pkt_data, pkt_size+AV_LZO_OUTPUT_PADDING);
            result = av_lzo1x_decode(pkt_data, &olen, data, &isize);
        } while (result==AV_LZO_OUTPUT_FULL && pkt_size<10000000);
        if (result)
            goto failed;
        pkt_size -= olen;
        break;
#if CONFIG_ZLIB
    case MATROSKA_TRACK_ENCODING_COMP_ZLIB: {
        z_stream zstream = {0};
        if (inflateInit(&zstream) != Z_OK)
            return -1;
        zstream.next_in = data;
        zstream.avail_in = isize;
        do {
            pkt_size *= 3;
            pkt_data = av_realloc(pkt_data, pkt_size);
            zstream.avail_out = pkt_size - zstream.total_out;
            zstream.next_out = pkt_data + zstream.total_out;
            result = inflate(&zstream, Z_NO_FLUSH);
        } while (result==Z_OK && pkt_size<10000000);
        pkt_size = zstream.total_out;
        inflateEnd(&zstream);
        if (result != Z_STREAM_END)
            goto failed;
        break;
    }
#endif
#if CONFIG_BZLIB
    case MATROSKA_TRACK_ENCODING_COMP_BZLIB: {
        bz_stream bzstream = {0};
        if (BZ2_bzDecompressInit(&bzstream, 0, 0) != BZ_OK)
            return -1;
        bzstream.next_in = data;
        bzstream.avail_in = isize;
        do {
            pkt_size *= 3;
            pkt_data = av_realloc(pkt_data, pkt_size);
            bzstream.avail_out = pkt_size - bzstream.total_out_lo32;
            bzstream.next_out = pkt_data + bzstream.total_out_lo32;
            result = BZ2_bzDecompress(&bzstream);
        } while (result==BZ_OK && pkt_size<10000000);
        pkt_size = bzstream.total_out_lo32;
        BZ2_bzDecompressEnd(&bzstream);
        if (result != BZ_STREAM_END)
            goto failed;
        break;
    }
#endif
    default:
        return -1;
    }
    *buf = pkt_data;
    *buf_size = pkt_size;
    return 0;
 failed:
    av_free(pkt_data);
    return -1;
}
['static int matroska_decode_buffer(uint8_t** buf, int* buf_size,\n                                  MatroskaTrack *track)\n{\n    MatroskaTrackEncoding *encodings = track->encodings.elem;\n    uint8_t* data = *buf;\n    int isize = *buf_size;\n    uint8_t* pkt_data = NULL;\n    int pkt_size = isize;\n    int result = 0;\n    int olen;\n    if (pkt_size >= 10000000)\n        return -1;\n    switch (encodings[0].compression.algo) {\n    case MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP:\n        return encodings[0].compression.settings.size;\n    case MATROSKA_TRACK_ENCODING_COMP_LZO:\n        do {\n            olen = pkt_size *= 3;\n            pkt_data = av_realloc(pkt_data, pkt_size+AV_LZO_OUTPUT_PADDING);\n            result = av_lzo1x_decode(pkt_data, &olen, data, &isize);\n        } while (result==AV_LZO_OUTPUT_FULL && pkt_size<10000000);\n        if (result)\n            goto failed;\n        pkt_size -= olen;\n        break;\n#if CONFIG_ZLIB\n    case MATROSKA_TRACK_ENCODING_COMP_ZLIB: {\n        z_stream zstream = {0};\n        if (inflateInit(&zstream) != Z_OK)\n            return -1;\n        zstream.next_in = data;\n        zstream.avail_in = isize;\n        do {\n            pkt_size *= 3;\n            pkt_data = av_realloc(pkt_data, pkt_size);\n            zstream.avail_out = pkt_size - zstream.total_out;\n            zstream.next_out = pkt_data + zstream.total_out;\n            result = inflate(&zstream, Z_NO_FLUSH);\n        } while (result==Z_OK && pkt_size<10000000);\n        pkt_size = zstream.total_out;\n        inflateEnd(&zstream);\n        if (result != Z_STREAM_END)\n            goto failed;\n        break;\n    }\n#endif\n#if CONFIG_BZLIB\n    case MATROSKA_TRACK_ENCODING_COMP_BZLIB: {\n        bz_stream bzstream = {0};\n        if (BZ2_bzDecompressInit(&bzstream, 0, 0) != BZ_OK)\n            return -1;\n        bzstream.next_in = data;\n        bzstream.avail_in = isize;\n        do {\n            pkt_size *= 3;\n            pkt_data = av_realloc(pkt_data, pkt_size);\n            bzstream.avail_out = pkt_size - bzstream.total_out_lo32;\n            bzstream.next_out = pkt_data + bzstream.total_out_lo32;\n            result = BZ2_bzDecompress(&bzstream);\n        } while (result==BZ_OK && pkt_size<10000000);\n        pkt_size = bzstream.total_out_lo32;\n        BZ2_bzDecompressEnd(&bzstream);\n        if (result != BZ_STREAM_END)\n            goto failed;\n        break;\n    }\n#endif\n    default:\n        return -1;\n    }\n    *buf = pkt_data;\n    *buf_size = pkt_size;\n    return 0;\n failed:\n    av_free(pkt_data);\n    return -1;\n}', 'void *av_realloc(void *ptr, size_t size)\n{\n#if CONFIG_MEMALIGN_HACK\n    int diff;\n#endif\n    if(size > (INT_MAX-16) )\n        return NULL;\n#if CONFIG_MEMALIGN_HACK\n    if(!ptr) return av_malloc(size);\n    diff= ((char*)ptr)[-1];\n    return (char*)realloc((char*)ptr - diff, size + diff) + diff;\n#else\n    return realloc(ptr, size);\n#endif\n}']