I think the following function in the file jdk/src/windows/native/java/io/WinNTFileSystem_md.c in http://download.java.net/openjdk/jdk6/promoted/b27/openjdk-6-src-b27-26_oct_2012.tar.gz neglects to free the memory used by frompath
or topath
if one of them is found to be NULL
...
JNIEXPORT jboolean JNICALL
Java_java_io_WinNTFileSystem_rename0(JNIEnv *env, jobject this, jobject from,
jobject to)
{
jboolean rv = JNI_FALSE;
WCHAR *frompath = fileToNTPath(env, from, ids.path);
WCHAR *topath = fileToNTPath(env, to, ids.path);
if (frompath == NULL || topath == NULL)
return JNI_FALSE;
if (_wrename(frompath, topath) == 0) {
rv = JNI_TRUE;
}
free(frompath);
free(topath);
return rv;
}
Am I missing something? Is this in fact a bug?
Resolved: Looking further into the details of the function pathToNTPath
in io_util_md.c, I can see that fileToNTPath
will only return NULL
in the case of an out-of-memory error, so I guess we don't care if we neglect to free something we malloc
ed when the JVM is about to crash! This still should be documented in the Java_java_io_WinNTFileSystem_rename0
function in my opinion though.