Fix memory leak in compositor code with RGB curve nodes.
[blender.git] / source / blender / compositor / operations / COM_CurveBaseOperation.cpp
1 /*
2  * Copyright 2011, Blender Foundation.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor: 
19  *              Jeroen Bakker 
20  *              Monique Dewanchand
21  */
22
23 #include "COM_CurveBaseOperation.h"
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 #  include "BKE_colortools.h"
29 #ifdef __cplusplus
30 }
31 #endif
32
33 CurveBaseOperation::CurveBaseOperation() : NodeOperation()
34 {
35         this->m_curveMapping = NULL;
36 }
37
38 CurveBaseOperation::~CurveBaseOperation()
39 {
40         if (this->m_curveMapping) {
41                 curvemapping_free(this->m_curveMapping);
42                 this->m_curveMapping = NULL;
43         }
44 }
45
46 void CurveBaseOperation::initExecution()
47 {
48         curvemapping_initialize(this->m_curveMapping);
49 }
50 void CurveBaseOperation::deinitExecution()
51 {
52         if (this->m_curveMapping) {
53                 curvemapping_free(this->m_curveMapping);
54                 this->m_curveMapping = NULL;
55         }
56 }
57
58 void CurveBaseOperation::setCurveMapping(CurveMapping *mapping)
59 {
60         /* duplicate the curve to avoid glitches while drawing, see bug [#32374] */
61         if (this->m_curveMapping) {
62                 curvemapping_free(this->m_curveMapping);
63         }
64         this->m_curveMapping = curvemapping_copy(mapping);
65 }