Skip Menu |

This queue is for tickets about the Win32-API CPAN distribution.

Report information
The Basics
Id: 12057
Status: resolved
Priority: 0/
Queue: Win32-API

People
Owner: BULKDD [...] cpan.org
Requestors: jeff.holt [...] hotsos.com
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: (no value)
Fixed in: (no value)



Subject: dll not unloaded if the first new fails
I have a problem that I think can be solved easily. Here's the pseudo code for my application. 1. Use new Win32::API to determine if A.DLL exports foo() 2. If it does, then "my product is enabled", otherwise replace A.DLL with Aprime.DLL 3. If the replace fails, then show which processes have A.DLL open Even if no other process loaded A.DLL, my process does. But step 1 fails to return a handle because the existing version of A.DLL doesn't have foo. And because step 1 doesn't return a handle I cannot unload A.DLL. I propose the following: If LoadLibrary() succeeds but the subsequent GetProcAddress() calls fail, then FreeLibrary() if Procedures{$dll} isn't defined or equals zero. I've attached the diff output.
$ diff APInew.pm API.pm 65a66 > $Libraries{$dll} = $hdll; 77,80c78 < unless ($proc) { < Win32::API::FreeLibrary($hdll) unless $Procedures{$dll}; < return undef; < } --- > return undef unless $proc; 111d108 < Win32::API::FreeLibrary($hdll) unless $Procedures{$dll};
From: bulk88 [...] hotmail.com
On Tue Mar 29 15:07:12 2005, guest wrote: Show quoted text
> I propose the following: > If LoadLibrary() succeeds but the subsequent GetProcAddress() calls > fail, then FreeLibrary() if Procedures{$dll} isn't defined or > equals zero. > > I've attached the diff output.
I dont like the patch, but this is absolutely a problem. We are leaking dll handles. It should be pretty easy to put a FreeLibrary line in this section in new sub. Show quoted text
________________________________________________ #### ...if all that fails, set $! accordingly if(!$hproc) { $! = Win32::GetLastError(); DEBUG "FAILED GetProcAddress for Proc '$proc': $!\n"; return undef; }
_________________________________________________
Was fixed in 0.69 and a test added to 00_API.t for this bug.