I have "adopted" some code that does some fancy stuff with graphics.
It is written in C++ and compiled into a callable DLL that I can use in my C# program.
(all the c++ source is available)
It works great and gives me exactly the features I need but it leaks memory like a sieve.
I figure I can fix it and give something back to the open source community as the original author is too busy with real work at the moment. :)
The trouble is my C++ is fairly average but hey I can google. I have fixed one gusher but I see a few blocks of code that look like this for example.
ImageData* img_data = new ImageData;
img_data->m_bytesPerPixel = m_bytesPerPixel;
img_data->AllocDataSpace(GetWidth(), GetHeight(), GetBytesPerPixel() * 8);
memcpy(img_data->m_data, m_data, GetSize());
img_data->m_width = m_width;
img_data->m_height = m_height;
My understanding is that the "new" in the first line is going to allocate some memory and there has to be a corresponding "delete img_data" somewhere else to deallocate the memory.
I searched the project and there isn't one.
I'd expect to be doing the delete in the same method that created it.
But img_data is being returned to the calling method so I can't delete it there.
I'm assuming that this is a leak but I don't know how to deal with it.
Any sugestions / points in the right direction would be very helpfull.
Thanks in Advance
Perhaps I didn't make this clear enough. Here are some more details. My c# code passes a file name to the c++ code contained within the DLL. The code in the DLL calculates if the document in the file has been scanned straight and returnes the angle of the document or 0 if it is square to the c# code. So clearly the problems lies within the c++ code.
Further investigation revealed that the example module shown below is never actually called.
If anyone would like to look at the code it is in this Code Project Article and a simple example VIsual Studio project to call and test the DLL is included.
Detect image skew angle and deskew image
Thanks for all your comments so far