GIDForums  

Go Back   GIDForums > Computer Programming Forums > FLTK Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 01-Dec-2007, 08:12
jutirain jutirain is offline
New Member
 
Join Date: Nov 2007
Posts: 6
jutirain is on a distinguished road

Memory leak caused by Box::draw()


Hi,

I've used valgrind and discovered that the following function may cause memory leak.

ImageBox is a user-defined class that heritage from Fl_Box.

image_mod is in the type of another image processing library. I copy it to temp_char_array to initialize Fl_RGB_Image.
(Actually I can use image_mod to initialize Fl_RGB_Image directly, but still cause memory leak, however)

Besides, the image show up on the window is correct, so the initialization of Fl_RGB_Image may not be the problem...

The valgrind output point out the problem to be libfontconfig.so, may not help, but the leak summary is listed below:

==11010== LEAK SUMMARY:
==11010== definitely lost: 806 bytes in 6 blocks.
==11010== indirectly lost: 848 bytes in 42 blocks.
==11010== possibly lost: 0 bytes in 0 blocks.
==11010== still reachable: 1,201,143 bytes in 2,859 blocks.
==11010== suppressed: 0 bytes in 0 blocks.
==11010== Reachable blocks (those to which a pointer was found) are not shown.
==11010== To see them, rerun with: --show-reachable=yes

No matter the image size, the leak size is always ( 806, 848 )

Any idea?

CPP / C++ / C Code:
void ImageBox::draw()
{
	// create a temporary char array which has the dimension [width * height * channels]
	unsigned char temp_char_array[ image_mod.width() * image_mod.height() * image_mod.channels() ] ;

	// stuff the temporary char array with the information in image_mod
	size_t cur_index = 0 ;
	for ( size_t y = 0 ; y < image_mod.height() ; ++y )
		for( size_t x = 0 ; x < image_mod.width() ; ++x )
			for( size_t c = 0 ; c < image_mod.channels() ; ++c )
			{
				temp_char_array[cur_index] = image_mod(x, y)[c] ;
				cur_index++ ;
			}

	Fl_RGB_Image temp(
			temp_char_array,
			image_mod.width(),
			image_mod.height(),
			image_mod.channels()) ;

	image( temp ) ;

	// using draw() of super class to do the rest (if any)
	Fl_Box::draw() ;	
}
 
 

Recent GIDBlogProblems with the Navy (Officers) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to fix memory leak possibly caused by libfontconfig.so? -- implied by valgrind jutirain C++ Forum 2 01-Dec-2007 07:02
Hard drive/CPU Diagnoses Issues binarybug Computer Hardware Forum 1 22-Jan-2007 19:23
Memory de-allocation during debugging gaoanyu C Programming Language 12 19-Dec-2005 04:50
Pointer Usage in C++: Beginner to Advanced varunhome C++ Forum 0 19-Aug-2005 09:25
[Tutorial] Pointers in C (Part I) Stack Overflow C Programming Language 1 08-Apr-2005 18:35

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 12:33.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.