qtdemux: fix leak by flushing previous sample info from trak
authorThiago Santos <thiagoss@osg.samsung.com>
Wed, 8 Jul 2015 00:31:08 +0000 (21:31 -0300)
committerThiago Santos <thiagoss@osg.samsung.com>
Wed, 8 Jul 2015 14:53:44 +0000 (11:53 -0300)
commit5994b30257415fc7d0b2a9b74e99eccdc98a305a
tree6cc351480c17da182ed1ee95b761099317a2c9cb
parent63f35eeb12944180d4c904e222977a0443d7d1ac
qtdemux: fix leak by flushing previous sample info from trak

In fragmented streaming, multiple moov/moof will be parsed and their
previously stored samples array might leak when new values are parsed.
The parse_trak and callees won't free the previously stored values
before parsing the new ones.

In step-by-step, this is what happens:

1) initial moov is parsed, traks as well, streams are created. The
   trak doesn't contain samples because they are in the moof's trun
   boxes. n_samples is set to 0 while parsing the trak and the samples
   array is still NULL.
2) moofs are parsed, and their trun boxes will increase n_samples and
   create/extend the samples array
3) At some point a new moov might be sent (bitrate switching, for example)
   and parsing the trak will overwrite n_samples with the values from
   this trak. If the n_samples is set to 0 qtdemux will assume that
   the samples array is NULL and will leak it when a new one is
   created for the subsequent moofs.

This patch makes qtdemux properly free previous sample data before
creating new ones and adds an assert to catch future occurrences of
this issue when the code changes.
gst/isomp4/qtdemux.c