Skip to content

Commit f2188e6

Browse files
authored
Merge pull request #71 from deltaoscarmike/memleaks_fixes
memleaks fixes
2 parents 1a32b44 + 40a5480 commit f2188e6

File tree

10 files changed

+50
-14
lines changed

10 files changed

+50
-14
lines changed

src/libprojectM/MilkdropPresetFactory/Expr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ class MultAndAddExpr : public Expr
180180
a(_a), b(_b), c(_c)
181181
{
182182
}
183+
~MultAndAddExpr() {
184+
delete a;
185+
delete b;
186+
delete c;
187+
}
183188
float eval(int mesh_i, int mesh_j)
184189
{
185190
float a_value = a->eval(mesh_i,mesh_j);

src/libprojectM/MilkdropPresetFactory/MilkdropPreset.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,7 @@ MilkdropPreset::~MilkdropPreset()
9393
delete(*pos);
9494
}
9595
customWaves.clear();
96-
customShapes.clear();
97-
presetOutputs().customWaves.clear();
98-
presetOutputs().customShapes.clear();
99-
presetOutputs().drawables.clear();
100-
96+
customShapes.clear();
10197
}
10298

10399
/* Adds a per pixel equation according to its string name. This

src/libprojectM/MilkdropPresetFactory/Parser.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,10 @@ Expr * Parser::parse_gen_expr ( std::istream & fs, TreeExpr * tree_expr, Milkdr
986986
return NULL;
987987
//std::cout << gen_expr << std::endl;
988988
Expr *opt = gen_expr->optimize();
989+
990+
if (opt != gen_expr) {
991+
delete gen_expr;
992+
}
989993
//std::cout << opt << std::endl << std::endl;
990994
return opt;
991995
}
@@ -2460,6 +2464,8 @@ int Parser::parse_shape_per_frame_init_eqn(std::istream & fs, CustomShape * cus
24602464

24612465
line_mode = CUSTOM_SHAPE_PER_FRAME_INIT_LINE_MODE;
24622466
init_cond->evaluate(true);
2467+
2468+
delete init_cond;
24632469
return PROJECTM_SUCCESS;
24642470
}
24652471

src/libprojectM/MilkdropPresetFactory/PresetFrameIO.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ PresetOutputs::~PresetOutputs()
119119
this->rot_mesh = free_mesh(this->rot_mesh);
120120
this->orig_x = free_mesh(this->orig_x);
121121
this->orig_y = free_mesh(this->orig_y);
122+
123+
customWaves.clear();
124+
customShapes.clear();
125+
drawables.clear();
122126
}
123127

124128

@@ -457,7 +461,6 @@ void PresetOutputs::Initialize ( int gx, int gy )
457461
this->gy = gy;
458462

459463
staticPerPixel = true;
460-
setStaticPerPixel(gx,gy);
461464

462465
assert(this->gx > 0);
463466
int x;

src/libprojectM/PCM.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ int PCM::maxsamples = 2048;
4242
// number of samples specified.
4343
#include <iostream>
4444
PCM::PCM() {
45-
initPCM( 2048 );
45+
_initPCM( 2048 );
4646

4747
#ifdef DEBUG
4848
std::cerr << "[PCM] MAX SAMPLES:" << maxsamples << std::endl;
4949
#endif
5050
}
5151

52-
void PCM::initPCM(int samples) {
52+
void PCM::_initPCM(int samples) {
5353
int i;
5454

5555
waveSmoothing = 0;

src/libprojectM/PCM.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ PCM {
5858
static int maxsamples;
5959
PCM();
6060
~PCM();
61-
void initPCM(int maxsamples);
6261
void addPCMfloat(const float *PCMdata, int samples);
6362
void addPCM16(short [2][512]);
6463
void addPCM16Data(const short* pcm_data, short samples);
@@ -68,6 +67,8 @@ PCM {
6867
void freePCM();
6968
int getPCMnew(float *PCMdata, int channel, int freq, float smoothing, int derive,int reset);
7069

70+
private:
71+
void _initPCM(int maxsamples);
7172

7273
};
7374

src/libprojectM/Renderer/RenderItemDistanceMetric.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
/// when they are dissimilar. If two render items cannot be compared, NOT_COMPARABLE_VALUE is returned.
2020
class RenderItemDistanceMetric : public std::binary_function<const RenderItem*, const RenderItem*, double> {
2121
public:
22+
virtual ~RenderItemDistanceMetric() { }
2223
const static double NOT_COMPARABLE_VALUE;
2324
virtual double operator()(const RenderItem * r1, const RenderItem * r2) const = 0;
2425
virtual TypeIdPair typeIdPair() const = 0;
@@ -103,7 +104,11 @@ typedef std::map<TypeIdPair, RenderItemDistanceMetric*> DistanceMetricMap;
103104
public:
104105

105106
MasterRenderItemDistance() {}
106-
virtual ~MasterRenderItemDistance() {}
107+
virtual ~MasterRenderItemDistance() {
108+
for (DistanceMetricMap::iterator it = _distanceMetricMap.begin(); it != _distanceMetricMap.end(); ++it)
109+
delete (it->second);
110+
_distanceMetricMap.clear();
111+
}
107112

108113
inline void addMetric(RenderItemDistanceMetric * fun) {
109114
_distanceMetricMap[fun->typeIdPair()] = fun;

src/libprojectM/Renderer/RenderItemMergeFunction.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ inline bool interpolate(bool a, bool b, float ratio)
3939
/// when they are dissimilar. If two render items cannot be compared, NOT_COMPARABLE_VALUE is returned.
4040
class RenderItemMergeFunction {
4141
public:
42+
virtual ~RenderItemMergeFunction() {}
4243
virtual RenderItem * operator()(const RenderItem * r1, const RenderItem * r2, double ratio) const = 0;
4344
virtual TypeIdPair typeIdPair() const = 0;
4445
};
@@ -201,7 +202,11 @@ typedef std::map<TypeIdPair, RenderItemMergeFunction*> MergeFunctionMap;
201202
public:
202203

203204
MasterRenderItemMerge() {}
204-
virtual ~MasterRenderItemMerge() {}
205+
virtual ~MasterRenderItemMerge() {
206+
for (MergeFunctionMap::iterator it = _mergeFunctionMap.begin(); it != _mergeFunctionMap.end(); ++it)
207+
delete (it->second);
208+
_mergeFunctionMap.clear();
209+
}
205210

206211
inline void add(RenderItemMergeFunction * fun) {
207212
_mergeFunctionMap[fun->typeIdPair()] = fun;

src/libprojectM/projectM.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ projectM::~projectM()
101101
_pcm = 0;
102102
}
103103

104+
if(timeKeeper) {
105+
delete timeKeeper;
106+
timeKeeper = NULL;
107+
}
108+
104109
delete(_pipelineContext);
105110
delete(_pipelineContext2);
106111
}
@@ -117,7 +122,8 @@ void projectM::projectM_resetTextures()
117122

118123

119124
projectM::projectM ( std::string config_file, int flags) :
120-
beatDetect ( 0 ), renderer ( 0 ), _pcm(0), m_presetPos(0), m_flags(flags), _pipelineContext(new PipelineContext()), _pipelineContext2(new PipelineContext())
125+
beatDetect ( 0 ), renderer ( 0 ), _pcm(0), m_presetPos(0), m_flags(flags), _pipelineContext(new PipelineContext()), _pipelineContext2(new PipelineContext()),
126+
timeKeeper(NULL), _matcher(NULL), _merger(NULL)
121127
{
122128
readConfig(config_file);
123129
projectM_reset();
@@ -126,7 +132,8 @@ beatDetect ( 0 ), renderer ( 0 ), _pcm(0), m_presetPos(0), m_flags(flags), _pip
126132
}
127133

128134
projectM::projectM(Settings settings, int flags):
129-
beatDetect ( 0 ), renderer ( 0 ), _pcm(0), m_presetPos(0), m_flags(flags), _pipelineContext(new PipelineContext()), _pipelineContext2(new PipelineContext())
135+
beatDetect ( 0 ), renderer ( 0 ), _pcm(0), m_presetPos(0), m_flags(flags), _pipelineContext(new PipelineContext()), _pipelineContext2(new PipelineContext()),
136+
timeKeeper(NULL), _matcher(NULL), _merger(NULL)
130137
{
131138
readSettings(settings);
132139
projectM_reset();
@@ -652,6 +659,15 @@ static void *thread_callback(void *prjm) {
652659

653660
m_presetLoader = 0;
654661

662+
if (_matcher) {
663+
delete _matcher;
664+
_matcher = NULL;
665+
}
666+
667+
if (_merger) {
668+
delete _merger;
669+
_merger = NULL;
670+
}
655671
}
656672

657673
/// @bug queuePreset case isn't handled

src/projectM-sdl/pmSDL.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ void projectMSDL::beginAudioCapture() {
9797
// allocate a buffer to store PCM data for feeding in
9898
unsigned int maxSamples = audioChannelsCount * audioSampleCount;
9999
SDL_PauseAudioDevice(audioDeviceID, false);
100-
pcm()->initPCM(2048);
101100
}
102101

103102
void projectMSDL::endAudioCapture() {

0 commit comments

Comments
 (0)