kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #12083
patch: possible memory leak in DXF outline import
In dxf2brd_items.cpp, bool DXF2BRD_CONVERTER::ImportDxfFile(), the DXF reader is not deleted if the read operation fails. The attached patch fixes the leak; it also removes the DXF reader pointer from the class structure since it is only used in the ImportDxfFile() routine.
- Cirilo
=== modified file 'pcbnew/import_dxf/dxf2brd_items.cpp'
--- pcbnew/import_dxf/dxf2brd_items.cpp 2013-12-19 11:33:57 +0000
+++ pcbnew/import_dxf/dxf2brd_items.cpp 2014-02-02 07:31:07 +0000
@@ -52,7 +52,6 @@
m_xOffset = 0.0; // X coord offset for conversion (in mm)
m_yOffset = 0.0; // Y coord offset for conversion (in mm)
m_Dfx2mm = 1.0; // The scale factor to convert DXF units to mm
- m_dxf = NULL;
m_brd = NULL;
m_version = 0;
m_defaultThickness = 0.1;
@@ -89,23 +88,24 @@
* with this filter.
*
* @param aFile = the full filename.
- * @param aLayersList = where to store the list of layer names
+ * @param aBoard = where to store the graphical items and text
*/
bool DXF2BRD_CONVERTER::ImportDxfFile( const wxString& aFile, BOARD* aBoard )
{
+ dxfRW* dxf = NULL;
+
m_brd = aBoard;
- m_dxf = new dxfRW( aFile.ToUTF8() );
- bool success = m_dxf->read( this, true );
+ dxf = new dxfRW( aFile.ToUTF8() );
- if( success==false )
- {
+ if( !dxf )
return false;
- }
-
- delete m_dxf;
- m_dxf = NULL;
- return true;
+
+ bool success = dxf->read( this, true );
+
+ delete dxf;
+
+ return success;
}
// Add aItem the the board
=== modified file 'pcbnew/import_dxf/dxf2brd_items.h'
--- pcbnew/import_dxf/dxf2brd_items.h 2013-10-30 12:14:45 +0000
+++ pcbnew/import_dxf/dxf2brd_items.h 2014-02-02 07:10:33 +0000
@@ -29,7 +29,6 @@
#include "drw_interface.h"
#include "wx/wx.h"
-class dxfRW;
class BOARD;
class BOARD_ITEM;
@@ -54,7 +53,6 @@
int m_brdLayer; // The board layer to place imported dfx items
int m_version; // the dxf version, not used here
std::string m_codePage; // The code page, not used here
- dxfRW* m_dxf; // the dxf reader
public:
DXF2BRD_CONVERTER();
Follow ups