On Wednesday 27 February 2002 11:21 am, Edwin Leuven wrote:
> > Do you get the crash if you comment out the call to free_color_table
> > entirely?
> 
> No crash when:
> 
> GImageXPM::Data::~Data()
>  {
> }

And what effect does the attached patch have? Apply from the graphics directory to 
current cvs. Or apply by hand; it ain't v. big.

Can't see why this woudl make a difference though. We shouldn't have any uninitialised 
pointers and free(0) shouldn't crash.

Could you shove some print statements in free_color_table and find out just when it 
crashes?

Angus
Index: GraphicsImageXPM.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/graphics/GraphicsImageXPM.C,v
retrieving revision 1.2
diff -u -p -r1.2 GraphicsImageXPM.C
--- GraphicsImageXPM.C	2002/02/27 11:43:04	1.2
+++ GraphicsImageXPM.C	2002/02/27 11:45:39
@@ -401,9 +401,8 @@ GImageXPM::Data::Data()
 
 GImageXPM::Data::~Data()
 {
-	// Introduce temporary memory leak to fix crash.
-//	if (colorTable_.unique())
-//		free_color_table(colorTable_.get(), ncolors_);
+	if (colorTable_.unique())
+		free_color_table(colorTable_.get(), ncolors_);
 }
 
 
@@ -584,14 +583,14 @@ void copy_color_table(XpmColor const * i
 void free_color_table(XpmColor * table, size_t size)
 {
 	for (size_t i = 0; i < size; ++i) {
-		free(table[i].string);
-		free(table[i].symbolic);
-		free(table[i].m_color);
-		free(table[i].g_color);
-		free(table[i].g4_color);
-		free(table[i].c_color);
+		if (table[i].string)   free(table[i].string);
+		if (table[i].symbolic) free(table[i].symbolic);
+		if (table[i].m_color)  free(table[i].m_color);
+		if (table[i].g_color)  free(table[i].g_color);
+		if (table[i].g4_color) free(table[i].g4_color);
+		if (table[i].c_color)  free(table[i].c_color);
 	}
-	free(table);
+	if (table) free(table);
 }
 
 

Reply via email to