6621569: Win32ShellFolder2 and Win32ShellFolderManager2 may leak native resources

Reviewed-by: malenkov
This commit is contained in:
Pavel Porvatov 2009-11-06 12:44:41 +03:00
parent fcfa835d86
commit e918d4b860
2 changed files with 31 additions and 25 deletions

View File

@ -693,6 +693,7 @@ final class Win32ShellFolder2 extends ShellFolder {
ArrayList<Win32ShellFolder2> list = new ArrayList<Win32ShellFolder2>();
long pEnumObjects = getEnumObjects(includeHiddenFiles);
if (pEnumObjects != 0) {
try {
long childPIDL;
int testedAttrs = ATTRIB_FILESYSTEM | ATTRIB_FILESYSANCESTOR;
do {
@ -715,8 +716,10 @@ final class Win32ShellFolder2 extends ShellFolder {
releasePIDL(childPIDL);
}
} while (childPIDL != 0 && !Thread.currentThread().isInterrupted());
} finally {
releaseEnumObjects(pEnumObjects);
}
}
return Thread.currentThread().isInterrupted()
? new File[0]
: list.toArray(new ShellFolder[list.size()]);

View File

@ -79,9 +79,12 @@ public class Win32ShellFolderManager2 extends ShellFolderManager {
// Shouldn't happen but watch for it anyway
throw new FileNotFoundException("File " + file.getAbsolutePath() + " not found");
}
Win32ShellFolder2 folder = createShellFolderFromRelativePIDL(parent, pIDL);
try {
return createShellFolderFromRelativePIDL(parent, pIDL);
} finally {
Win32ShellFolder2.releasePIDL(pIDL);
return folder;
}
}
static Win32ShellFolder2 createShellFolderFromRelativePIDL(Win32ShellFolder2 parent, long pIDL)