Fix memory leak in IDF importer and add C++ build configuration symbol checks.

This commit is contained in:
Nicolas Planel
2015-06-13 12:26:06 -04:00
committed by Wayne Stambaugh
3 changed files with 14 additions and 6 deletions
+3
View File
@@ -83,6 +83,9 @@ macro( perform_feature_checks )
check_symbol_exists( strncasecmp "strings.h" HAVE_STRNCASECMP )
check_symbol_exists( strtok_r "string.h" HAVE_STRTOKR )
check_cxx_symbol_exists( strcasecmp "string.h" HAVE_STRCASECMP )
check_cxx_symbol_exists( strncasecmp "string.h" HAVE_STRNCASECMP )
# Some platforms define malloc and free in malloc.h instead of stdlib.h.
check_symbol_exists( malloc "stdlib.h" MALLOC_IN_STDLIB_H )
+3
View File
@@ -2,6 +2,7 @@ include_directories(
"${CMAKE_SOURCE_DIR}/lib_dxf"
"${CMAKE_SOURCE_DIR}/utils/idftools"
${OPENGL_INCLUDE_DIR}
${Boost_INCLUDE_DIR}
)
link_directories(
@@ -17,6 +18,8 @@ add_executable( idfrect idf_rect.cpp )
add_executable( dxf2idf dxf2idfmain.cpp dxf2idf.cpp )
add_executable( idf2vrml idf2vrml.cpp )
add_dependencies( idf2vrml boost )
target_link_libraries( dxf2idf lib_dxf idf3 ${wxWidgets_LIBRARIES} )
target_link_libraries( idf2vrml idf3 ${OPENGL_LIBRARIES} ${wxWidgets_LIBRARIES} )
+8 -6
View File
@@ -49,6 +49,7 @@
#include <algorithm>
#include <libgen.h>
#include <unistd.h>
#include <boost/ptr_container/ptr_map.hpp>
#include <idf_helpers.h>
#include <idf_common.h>
@@ -63,6 +64,7 @@ extern char* optarg;
extern int optopt;
using namespace std;
using namespace boost;
#define CLEANUP do { \
setlocale( LC_ALL, "C" ); \
@@ -122,7 +124,7 @@ bool WriteTriangles( std::ofstream& file, VRML_IDS* vID, VRML_LAYER* layer, bool
bool top, double top_z, double bottom_z, int precision, bool compact );
inline void TransformPoint( IDF_SEGMENT& seg, double frac, bool bottom,
double dX, double dY, double angle );
VRML_IDS* GetColor( std::map<std::string, VRML_IDS*>& cmap,
VRML_IDS* GetColor( boost::ptr_map<const std::string, VRML_IDS>& cmap,
int& index, const std::string& uid );
@@ -743,7 +745,7 @@ bool MakeComponents( IDF3_BOARD& board, std::ofstream& file, bool compact )
bool bottom;
IDF3::IDF_LAYER lyr;
std::map< std::string, VRML_IDS*> cmap; // map colors by outline UID
boost::ptr_map< const std::string, VRML_IDS> cmap; // map colors by outline UID
VRML_IDS* vcp;
IDF3_COMP_OUTLINE* pout;
@@ -861,14 +863,14 @@ bool MakeComponents( IDF3_BOARD& board, std::ofstream& file, bool compact )
}
VRML_IDS* GetColor( std::map<std::string, VRML_IDS*>& cmap, int& index, const std::string& uid )
VRML_IDS* GetColor( boost::ptr_map<const std::string, VRML_IDS>& cmap, int& index, const std::string& uid )
{
static int refnum = 0;
if( index < 2 )
index = 2; // 0 and 1 are special (BOARD, UID=NOGEOM_NOPART)
std::map<std::string, VRML_IDS*>::iterator cit = cmap.find( uid );
boost::ptr_map<const std::string, VRML_IDS>::iterator cit = cmap.find( uid );
if( cit == cmap.end() )
{
@@ -886,7 +888,7 @@ VRML_IDS* GetColor( std::map<std::string, VRML_IDS*>& cmap, int& index, const st
if( showObjectMapping )
cout << "* " << ostr.str() << " = '" << uid << "'\n";
cmap.insert( std::pair<std::string, VRML_IDS*>(uid, id) );
cmap.insert( uid, id );
if( index >= NCOLORS )
index = 2;
@@ -922,7 +924,7 @@ bool MakeOtherOutlines( IDF3_BOARD& board, std::ofstream& file )
bool bottom;
int nvcont;
std::map< std::string, VRML_IDS*> cmap; // map colors by outline UID
boost::ptr_map< const std::string, VRML_IDS> cmap; // map colors by outline UID
VRML_IDS* vcp;
OTHER_OUTLINE* pout;