On Wed, 28 Apr 2021 06:38:57 GMT, Wang Huang <whu...@openjdk.org> wrote:
> Dear All, > I find a memory leak in `appendBootClassPath()` > https://github.com/openjdk/jdk/blob/75a2354dc276e107d64516d20fc72bc7ef3d5f86/src/java.instrument/share/native/libinstrument/InvocationAdapter.c#L950 > * we malloc `resolved` from resolve(parent, path) > * we use `resolved` in line 951 > * we don't free() this memory after using. > > I think we can fix this bug by adding a free() after line 951 as my commit. > Thank you for your review. Any suggestion is welcome. > > Yours , > Wang Huang Hi, I didn't find it immediately obvious that this was safe, but I followed things and think that it is correct: The malloc'd pointer gets passed to... JvmtiEnv::AddToBootstrapClassLoaderSearch(const char* segment) { which calls ClassPathZipEntry* ClassLoader::create_class_path_zip_entry(const char *path, bool is_boot_append) { ..which calls char* ClassLoader::get_canonical_path(const char* orig, Thread* thread) { ...which makes a copy of the string: char* orig_copy = NEW_RESOURCE_ARRAY_IN_THREAD(thread, char, strlen(orig)+1); strcpy(orig_copy, orig); ...and doesn't apear to keep the pointer. So yes I think we should free it. 8-) ------------- PR: https://git.openjdk.java.net/jdk/pull/3751