Fix a memory leak
If nLayers is insane, we won't properly free `video` in the `fail`
block, since the nLayers check is done before we assign `video` to
`decCtrl->videoDecoderData`.
Caught by the static analyzer.
Bug: None
Test: Ran the analyzer again. It no longer complains about this leak.
Change-Id: I6ec612b75f9d325c7693f670a96d95363f6bb2ae
diff --git a/media/libstagefright/codecs/m4v_h263/dec/src/pvdec_api.cpp b/media/libstagefright/codecs/m4v_h263/dec/src/pvdec_api.cpp
index 8d5d071..75ca846 100644
--- a/media/libstagefright/codecs/m4v_h263/dec/src/pvdec_api.cpp
+++ b/media/libstagefright/codecs/m4v_h263/dec/src/pvdec_api.cpp
@@ -107,6 +107,7 @@
#else
if ((size_t)nLayers > SIZE_MAX / sizeof(Vol *)) {
status = PV_FALSE;
+ oscl_free(video);
goto fail;
}
@@ -115,7 +116,8 @@
if (video->vol == NULL) status = PV_FALSE;
video->memoryUsage += nLayers * sizeof(Vol *);
-
+ /* be sure not to leak any previous state */
+ PVCleanUpVideoDecoder(decCtrl);
/* we need to setup this pointer for the application to */
/* pass it around. */
decCtrl->videoDecoderData = (void *) video;