From 35eb6adc555726e152903e5cc55dd88d3bd460c3 Mon Sep 17 00:00:00 2001 From: "FeRD (Frank Dana)" Date: Thu, 11 Jul 2019 05:00:47 -0400 Subject: [PATCH] Clean up allocated memory in JSON code --- src/CacheDisk.cpp | 6 +++++- src/CacheMemory.cpp | 4 +++- src/ChunkReader.cpp | 3 ++- src/Clip.cpp | 4 +++- src/Color.cpp | 2 ++ src/Coordinate.cpp | 4 +++- src/DecklinkReader.cpp | 4 +++- src/DummyReader.cpp | 4 +++- src/EffectBase.cpp | 4 +++- src/FFmpegReader.cpp | 2 ++ src/FrameMapper.cpp | 4 +++- src/ImageReader.cpp | 2 ++ src/KeyFrame.cpp | 4 +++- src/Point.cpp | 4 +++- src/Profiles.cpp | 4 +++- src/QtImageReader.cpp | 4 +++- src/TextReader.cpp | 4 +++- src/Timeline.cpp | 8 ++++++-- src/WriterBase.cpp | 4 +++- src/effects/Bars.cpp | 5 +++-- src/effects/Blur.cpp | 5 +++-- src/effects/Brightness.cpp | 5 +++-- src/effects/ChromaKey.cpp | 4 +++- src/effects/ColorShift.cpp | 5 +++-- src/effects/Crop.cpp | 2 ++ src/effects/Deinterlace.cpp | 4 +++- src/effects/Hue.cpp | 5 +++-- src/effects/Mask.cpp | 4 +++- src/effects/Negate.cpp | 4 +++- src/effects/Pixelate.cpp | 5 +++-- src/effects/Saturation.cpp | 5 +++-- src/effects/Shift.cpp | 5 +++-- src/effects/Wave.cpp | 5 +++-- tests/Clip_Tests.cpp | 4 ++++ 34 files changed, 103 insertions(+), 39 deletions(-) diff --git a/src/CacheDisk.cpp b/src/CacheDisk.cpp index 4d446746..ee80c21f 100644 --- a/src/CacheDisk.cpp +++ b/src/CacheDisk.cpp @@ -495,6 +495,8 @@ Json::Value CacheDisk::JsonValue() { string errors; bool success = reader->parse( json_ranges.c_str(), json_ranges.c_str() + json_ranges.size(), &ranges, &errors ); + delete reader; + if (success) root["ranges"] = ranges; @@ -512,7 +514,9 @@ void CacheDisk::SetJson(string value) { string errors; bool success = reader->parse( value.c_str(), - value.c_str() + value.size(), &root, &errors ); + value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); diff --git a/src/CacheMemory.cpp b/src/CacheMemory.cpp index 4de6bb1f..fd1af22f 100644 --- a/src/CacheMemory.cpp +++ b/src/CacheMemory.cpp @@ -345,10 +345,11 @@ Json::Value CacheMemory::JsonValue() { Json::Value ranges; Json::CharReaderBuilder rbuilder; Json::CharReader* reader(rbuilder.newCharReader()); - + string errors; bool success = reader->parse( json_ranges.c_str(), json_ranges.c_str() + json_ranges.size(), &ranges, &errors ); + delete reader; if (success) root["ranges"] = ranges; @@ -368,6 +369,7 @@ void CacheMemory::SetJson(string value) { string errors; bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); diff --git a/src/ChunkReader.cpp b/src/ChunkReader.cpp index 8d5b466e..170808e2 100644 --- a/src/ChunkReader.cpp +++ b/src/ChunkReader.cpp @@ -285,10 +285,11 @@ void ChunkReader::SetJson(string value) { Json::Value root; Json::CharReaderBuilder rbuilder; Json::CharReader* reader(rbuilder.newCharReader()); - + string errors; bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); diff --git a/src/Clip.cpp b/src/Clip.cpp index bddcd0c9..8f72ffb8 100644 --- a/src/Clip.cpp +++ b/src/Clip.cpp @@ -796,10 +796,12 @@ void Clip::SetJson(string value) { Json::Value root; Json::CharReaderBuilder rbuilder; Json::CharReader* reader(rbuilder.newCharReader()); - + string errors; bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); diff --git a/src/Color.cpp b/src/Color.cpp index 21c3f146..0736eb63 100644 --- a/src/Color.cpp +++ b/src/Color.cpp @@ -116,6 +116,8 @@ void Color::SetJson(string value) { string errors; bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); diff --git a/src/Coordinate.cpp b/src/Coordinate.cpp index 5baeb5bf..a2f40e46 100644 --- a/src/Coordinate.cpp +++ b/src/Coordinate.cpp @@ -77,8 +77,10 @@ void Coordinate::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); diff --git a/src/DecklinkReader.cpp b/src/DecklinkReader.cpp index 230a6689..21e20b1f 100644 --- a/src/DecklinkReader.cpp +++ b/src/DecklinkReader.cpp @@ -272,8 +272,10 @@ void DecklinkReader::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); diff --git a/src/DummyReader.cpp b/src/DummyReader.cpp index aa1e6a56..3c66e9e0 100644 --- a/src/DummyReader.cpp +++ b/src/DummyReader.cpp @@ -150,8 +150,10 @@ void DummyReader::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); diff --git a/src/EffectBase.cpp b/src/EffectBase.cpp index 9bf30986..f9f8623b 100644 --- a/src/EffectBase.cpp +++ b/src/EffectBase.cpp @@ -106,8 +106,10 @@ void EffectBase::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); diff --git a/src/FFmpegReader.cpp b/src/FFmpegReader.cpp index 10d89051..40e29e03 100644 --- a/src/FFmpegReader.cpp +++ b/src/FFmpegReader.cpp @@ -2431,6 +2431,8 @@ void FFmpegReader::SetJson(string value) { string errors; bool success = reader->parse(value.c_str(), value.c_str() + value.size(), &root, &errors); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); diff --git a/src/FrameMapper.cpp b/src/FrameMapper.cpp index 1f6b7629..8d362381 100644 --- a/src/FrameMapper.cpp +++ b/src/FrameMapper.cpp @@ -701,8 +701,10 @@ void FrameMapper::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); diff --git a/src/ImageReader.cpp b/src/ImageReader.cpp index 62439d82..bafe76fe 100644 --- a/src/ImageReader.cpp +++ b/src/ImageReader.cpp @@ -165,6 +165,8 @@ void ImageReader::SetJson(string value) { string errors; bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); diff --git a/src/KeyFrame.cpp b/src/KeyFrame.cpp index 31393d17..5c79fe27 100644 --- a/src/KeyFrame.cpp +++ b/src/KeyFrame.cpp @@ -373,8 +373,10 @@ void Keyframe::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); diff --git a/src/Point.cpp b/src/Point.cpp index b0e85658..23b0159a 100644 --- a/src/Point.cpp +++ b/src/Point.cpp @@ -140,8 +140,10 @@ void Point::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); diff --git a/src/Profiles.cpp b/src/Profiles.cpp index 9c2b3014..fec06cfa 100644 --- a/src/Profiles.cpp +++ b/src/Profiles.cpp @@ -171,8 +171,10 @@ void Profile::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); diff --git a/src/QtImageReader.cpp b/src/QtImageReader.cpp index af12add4..a291ac92 100644 --- a/src/QtImageReader.cpp +++ b/src/QtImageReader.cpp @@ -304,8 +304,10 @@ void QtImageReader::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); diff --git a/src/TextReader.cpp b/src/TextReader.cpp index 9c664535..9cb75881 100644 --- a/src/TextReader.cpp +++ b/src/TextReader.cpp @@ -224,8 +224,10 @@ void TextReader::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); diff --git a/src/Timeline.cpp b/src/Timeline.cpp index 7636de7d..16ae2f6c 100644 --- a/src/Timeline.cpp +++ b/src/Timeline.cpp @@ -1034,8 +1034,10 @@ void Timeline::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -1131,8 +1133,10 @@ void Timeline::ApplyJsonDiff(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success || !root.isArray()) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid).", ""); diff --git a/src/WriterBase.cpp b/src/WriterBase.cpp index bc16e7e0..729f52e8 100644 --- a/src/WriterBase.cpp +++ b/src/WriterBase.cpp @@ -203,8 +203,10 @@ void WriterBase::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); diff --git a/src/effects/Bars.cpp b/src/effects/Bars.cpp index 4320e618..b85cd454 100644 --- a/src/effects/Bars.cpp +++ b/src/effects/Bars.cpp @@ -145,8 +145,10 @@ void Bars::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -207,4 +209,3 @@ string Bars::PropertiesJSON(int64_t requested_frame) { // Return formatted string return root.toStyledString(); } - diff --git a/src/effects/Blur.cpp b/src/effects/Blur.cpp index db036133..f5cad9d9 100644 --- a/src/effects/Blur.cpp +++ b/src/effects/Blur.cpp @@ -282,8 +282,10 @@ void Blur::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -338,4 +340,3 @@ string Blur::PropertiesJSON(int64_t requested_frame) { // Return formatted string return root.toStyledString(); } - diff --git a/src/effects/Brightness.cpp b/src/effects/Brightness.cpp index 67d45824..c32475b6 100644 --- a/src/effects/Brightness.cpp +++ b/src/effects/Brightness.cpp @@ -136,8 +136,10 @@ void Brightness::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -186,4 +188,3 @@ string Brightness::PropertiesJSON(int64_t requested_frame) { // Return formatted string return root.toStyledString(); } - diff --git a/src/effects/ChromaKey.cpp b/src/effects/ChromaKey.cpp index 397c7ab1..6825eb86 100644 --- a/src/effects/ChromaKey.cpp +++ b/src/effects/ChromaKey.cpp @@ -129,8 +129,10 @@ void ChromaKey::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); diff --git a/src/effects/ColorShift.cpp b/src/effects/ColorShift.cpp index f4fab883..218d47cd 100644 --- a/src/effects/ColorShift.cpp +++ b/src/effects/ColorShift.cpp @@ -228,8 +228,10 @@ void ColorShift::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -296,4 +298,3 @@ string ColorShift::PropertiesJSON(int64_t requested_frame) { // Return formatted string return root.toStyledString(); } - diff --git a/src/effects/Crop.cpp b/src/effects/Crop.cpp index 99f8f124..67c61f1e 100644 --- a/src/effects/Crop.cpp +++ b/src/effects/Crop.cpp @@ -146,6 +146,8 @@ void Crop::SetJson(string value) { string errors; bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); diff --git a/src/effects/Deinterlace.cpp b/src/effects/Deinterlace.cpp index c698dbd1..6e7f22f3 100644 --- a/src/effects/Deinterlace.cpp +++ b/src/effects/Deinterlace.cpp @@ -123,8 +123,10 @@ void Deinterlace::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); diff --git a/src/effects/Hue.cpp b/src/effects/Hue.cpp index a75b4a1f..5739e3f4 100644 --- a/src/effects/Hue.cpp +++ b/src/effects/Hue.cpp @@ -130,8 +130,10 @@ void Hue::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -177,4 +179,3 @@ string Hue::PropertiesJSON(int64_t requested_frame) { // Return formatted string return root.toStyledString(); } - diff --git a/src/effects/Mask.cpp b/src/effects/Mask.cpp index b952ba62..9e20b2cb 100644 --- a/src/effects/Mask.cpp +++ b/src/effects/Mask.cpp @@ -183,8 +183,10 @@ void Mask::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); diff --git a/src/effects/Negate.cpp b/src/effects/Negate.cpp index 1b9decdc..8451888f 100644 --- a/src/effects/Negate.cpp +++ b/src/effects/Negate.cpp @@ -84,8 +84,10 @@ void Negate::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); diff --git a/src/effects/Pixelate.cpp b/src/effects/Pixelate.cpp index 95d88b71..19324def 100644 --- a/src/effects/Pixelate.cpp +++ b/src/effects/Pixelate.cpp @@ -141,8 +141,10 @@ void Pixelate::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -200,4 +202,3 @@ string Pixelate::PropertiesJSON(int64_t requested_frame) { // Return formatted string return root.toStyledString(); } - diff --git a/src/effects/Saturation.cpp b/src/effects/Saturation.cpp index 4278b0b8..b101d96a 100644 --- a/src/effects/Saturation.cpp +++ b/src/effects/Saturation.cpp @@ -141,8 +141,10 @@ void Saturation::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -188,4 +190,3 @@ string Saturation::PropertiesJSON(int64_t requested_frame) { // Return formatted string return root.toStyledString(); } - diff --git a/src/effects/Shift.cpp b/src/effects/Shift.cpp index 0e802c99..d5445add 100644 --- a/src/effects/Shift.cpp +++ b/src/effects/Shift.cpp @@ -161,8 +161,10 @@ void Shift::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -211,4 +213,3 @@ string Shift::PropertiesJSON(int64_t requested_frame) { // Return formatted string return root.toStyledString(); } - diff --git a/src/effects/Wave.cpp b/src/effects/Wave.cpp index cfcb70c7..6733b7dd 100644 --- a/src/effects/Wave.cpp +++ b/src/effects/Wave.cpp @@ -144,8 +144,10 @@ void Wave::SetJson(string value) { Json::CharReader* reader(rbuilder.newCharReader()); string errors; - bool success = reader->parse( value.c_str(), + bool success = reader->parse( value.c_str(), value.c_str() + value.size(), &root, &errors ); + delete reader; + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -203,4 +205,3 @@ string Wave::PropertiesJSON(int64_t requested_frame) { // Return formatted string return root.toStyledString(); } - diff --git a/tests/Clip_Tests.cpp b/tests/Clip_Tests.cpp index 6c60bedd..a43b8faa 100644 --- a/tests/Clip_Tests.cpp +++ b/tests/Clip_Tests.cpp @@ -117,6 +117,7 @@ TEST(Clip_Properties) string errors; bool success = reader->parse( properties.c_str(), properties.c_str() + properties.size(), &root, &errors ); + if (!success) // Raise exception throw InvalidJSON("JSON could not be parsed (or is invalid)", ""); @@ -208,6 +209,9 @@ TEST(Clip_Properties) throw InvalidJSON("JSON is invalid (missing keys or invalid data types)", ""); } + + // Free up the reader we allocated + delete reader; } TEST(Clip_Effects)