Skip to content

Commit 833fcb8

Browse files
author
Chris Kirmse
committed
fix a number of memory leaks
- some were with libav functions - same were due to non-virtual destructors
1 parent 17a2258 commit 833fcb8

20 files changed

+63
-30
lines changed

include/CacheBase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ namespace openshot {
6060
/// @param max_bytes The maximum bytes to allow in the cache. Once exceeded, the cache will purge the oldest frames.
6161
CacheBase(int64_t max_bytes);
6262

63+
virtual ~CacheBase();
64+
6365
/// @brief Add a Frame to the cache
6466
/// @param frame The openshot::Frame object needing to be cached.
6567
virtual void Add(std::shared_ptr<Frame> frame) = 0;

include/CacheMemory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ namespace openshot {
7171
CacheMemory(int64_t max_bytes);
7272

7373
// Default destructor
74-
~CacheMemory();
74+
virtual ~CacheMemory();
7575

7676
/// @brief Add a Frame to the cache
7777
/// @param frame The openshot::Frame object needing to be cached.

include/Clip.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ namespace openshot {
160160
Clip(ReaderBase* new_reader);
161161

162162
/// Destructor
163-
~Clip();
163+
virtual ~Clip();
164164

165165
/// @brief Add an effect to the clip
166166
/// @param effect Add an effect to the clip. An effect can modify the audio or video of an openshot::Frame.

include/ClipBase.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ namespace openshot {
6969

7070
/// Constructor for the base clip
7171
ClipBase() { };
72+
virtual ~ClipBase();
7273

7374
// Compare a clip using the Position() property
7475
bool operator< ( ClipBase& a) { return (Position() < a.Position()); }

include/FFmpegReader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ namespace openshot {
243243
FFmpegReader(string path, bool inspect_reader);
244244

245245
/// Destructor
246-
~FFmpegReader();
246+
virtual ~FFmpegReader();
247247

248248
/// Close File
249249
void Close();

include/FFmpegUtilities.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@
209209
#define AV_FORMAT_NEW_STREAM(oc, st_codec, av_codec, av_st) av_st = avformat_new_stream(oc, NULL);\
210210
if (!av_st) \
211211
throw OutOfMemory("Could not allocate memory for the video stream.", path); \
212-
c = avcodec_alloc_context3(av_codec); \
213-
st_codec = c; \
214-
av_st->codecpar->codec_id = av_codec->id;
212+
avcodec_get_context_defaults3(av_st->codec, av_codec); \
213+
c = av_st->codec; \
214+
st_codec = c;
215215
#define AV_COPY_PARAMS_FROM_CONTEXT(av_stream, av_codec) avcodec_parameters_from_context(av_stream->codecpar, av_codec);
216216
#elif LIBAVFORMAT_VERSION_MAJOR >= 55
217217
#define AV_REGISTER_ALL av_register_all();

include/Frame.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ namespace openshot
159159
Frame& operator= (const Frame& other);
160160

161161
/// Destructor
162-
~Frame();
162+
virtual ~Frame();
163163

164164
/// Add (or replace) pixel data to the frame (based on a solid color)
165165
void AddColor(int new_width, int new_height, string new_color);

include/FrameMapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ namespace openshot
170170
FrameMapper(ReaderBase *reader, Fraction target_fps, PulldownType target_pulldown, int target_sample_rate, int target_channels, ChannelLayout target_channel_layout);
171171

172172
/// Destructor
173-
~FrameMapper();
173+
virtual ~FrameMapper();
174174

175175
/// Change frame rate or audio mapping details
176176
void ChangeMapping(Fraction target_fps, PulldownType pulldown, int target_sample_rate, int target_channels, ChannelLayout target_channel_layout);

include/QtImageReader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ namespace openshot
8181
/// when you are inflating the object using JSON after instantiating it.
8282
QtImageReader(string path, bool inspect_reader);
8383

84+
virtual ~QtImageReader();
85+
8486
/// Close File
8587
void Close();
8688

include/ReaderBase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ namespace openshot
107107
/// Constructor for the base reader, where many things are initialized.
108108
ReaderBase();
109109

110+
virtual ~ReaderBase();
111+
110112
/// Information about the current media file
111113
ReaderInfo info;
112114

0 commit comments

Comments
 (0)