APOLLO & ECW/JP2 Discussions

Wondering how others have configured their ERDAS APOLLO server or what data they are crawling? The ERDAS APOLLO Discussion board is a place to find information, share ideas and more. Join the community, connect, contribute and share.
Showing results for 
Search instead for 
Do you mean 
Occasional Visitor
Posts: 1
Registered: ‎02-01-2016
Accepted Solution

Handle leak in ERDAS ECW JPEG 2000 SDK

Hi! I've got a problem with the ERDAS ECW JPEG 2000 SDK version 5.2.1. I'm reading filenames from a database table and try to open them with the library function from the NCSECWCompatibility header. Some - that is, most - of these file actually do not exist, and when I try to open them there is a Handle leak.


 A small test app to reproduce the problem is this:

#include "NCSECWClient.h"
#include "NCSECWCompatibility.h"

int testRun(HANDLE process, const std::string& filename);
void printHandles(HANDLE process);

int main(int argc, char** argv)
	std::cout << "Testing ERDAS ECW SDK / ECW32 for handle leak..." << std::endl;
	auto process = GetCurrentProcess();
	std::string filename = "D:\\Test.sid";
	std::cout << "Using file \"" << filename << "\"." << std::endl;

	return testRun(process, filename);

int testRun(HANDLE process, const std::string& filename)
		char ecwError[256];
		for (size_t k = 0; k < 5000; ++k)
			NCSFileView* fileView = nullptr;
			std::cout << std::endl;
			auto res = NCScbmOpenFileView(filename.c_str(), &fileView, nullptr);
			printHandles(process);		// +3 Handles due to NCScbmOpenFileView
			if (res != NCS_SUCCESS)
				strcpy_s(ecwError, NCSGetErrorText(res));
				std::cout << "ECW Error: " << ecwError << std::endl;
			if (fileView)
				NCScbmCloseFileViewEx(fileView, TRUE);
				printHandles(process);	// -2 Handles due to NCScbmCloseFileViewEx
	catch (std::exception& exc)
		std::cout << exc.what() << std::endl;
		return 1;
	return 0;

As you can see in the comments, opening the (non-existent) file creates three handles, whereas closing it releases two. I'm using GetProcessHandleCount (Win32 API) inside the printHandles function to display these numbers; the overall number of handles can also be viewed with Task Manager.

Using Process Explorer from the Sysinternals Suite I've found out that the handles being created inside the library function are Event Handles - in case that's helpful.


Please note that this handle leak does not occurs if the filename has the extension .ecw. In this example, .sid (for MrSID) is used, but the problem also exists with .png, .jpg, .jpeg, .txt etc.


Besides not using the library with files having another extension that .ecw, is there any workaround or bugfix for this problem?


Posts: 1
Registered: ‎02-02-2016

Re: Handle leak in ERDAS ECW JPEG 2000 SDK

Hi Matz,


Thanks for reporting this issue to us.  It is a bug and an issue has been created to address it in the next SDK release.