Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8266187: Memory leak in appendBootClassPath() #3751

Closed
wants to merge 2 commits into from

Conversation

@Wanghuang-Huawei
Copy link

@Wanghuang-Huawei Wanghuang-Huawei commented Apr 28, 2021

Dear All,
I find a memory leak in appendBootClassPath()

  • 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


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

Reviewers

Contributors

  • Wang Huang <whuang@openjdk.org>
  • Sun Jianye <sunjianye@huawei.com>

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/3751/head:pull/3751
$ git checkout pull/3751

Update a local copy of the PR:
$ git checkout pull/3751
$ git pull https://git.openjdk.java.net/jdk pull/3751/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 3751

View PR using the GUI difftool:
$ git pr show -t 3751

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/3751.diff

@Wanghuang-Huawei
Copy link
Author

@Wanghuang-Huawei Wanghuang-Huawei commented Apr 28, 2021

/contributor add Wang Huang whuang@openjdk.org
/contributor add Sun Jianye sunjianye@huawei.com

Loading

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Apr 28, 2021

👋 Welcome back whuang! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

Loading

@openjdk openjdk bot added the rfr label Apr 28, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Apr 28, 2021

@Wanghuang-Huawei
Contributor Wang Huang <whuang@openjdk.org> successfully added.

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Apr 28, 2021

@Wanghuang-Huawei
Contributor Sun Jianye <sunjianye@huawei.com> successfully added.

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Apr 28, 2021

@Wanghuang-Huawei The following label will be automatically applied to this pull request:

  • serviceability

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

Loading

@mlbridge
Copy link

@mlbridge mlbridge bot commented Apr 28, 2021

Webrevs

Loading

@kevinjwalls
Copy link

@kevinjwalls kevinjwalls commented Apr 28, 2021

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-)

Loading

@Wanghuang-Huawei
Copy link
Author

@Wanghuang-Huawei Wanghuang-Huawei commented Apr 29, 2021

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-)

Thank you for your review and explanation.

Loading

Copy link

@Hamlin-Li Hamlin-Li left a comment

looks good.

Loading

@openjdk
Copy link

@openjdk openjdk bot commented Apr 30, 2021

@Wanghuang-Huawei This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8266187: Memory leak in appendBootClassPath()

Co-authored-by: Wang Huang <whuang@openjdk.org>
Co-authored-by: Sun Jianye <sunjianye@huawei.com>
Reviewed-by: kevinw, mli, alanb

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 72 new commits pushed to the master branch:

  • f86b70c: 8266328: C2: Remove InlineWarmCalls
  • 928d632: 8252237: C2: Call to compute_separating_interferences has wrong argument order
  • 50fa162: 8266389: ProblemList java/awt/Graphics2D/DrawString/DrawRotatedStringUsingRotatedFont.java on generic-all
  • dd05158: 8266155: Convert java.base to use Stream.toList()
  • c36c63a: 8260560: convert jdeps and jdeprscan tools to use Stream.toList()
  • 096e9e5: 8266318: Switch to macos prefix for macOS bundles
  • 0544a73: 8255227: java/net/httpclient/FlowAdapterPublisherTest.java intermittently failing with TestServer: start exception: java.io.IOException: Invalid preface
  • 48bb996: 8266220: keytool still prompt for store password on a password-less pkcs12 file if -storetype pkcs12 is specified
  • 87de5b7: 8266040: Lanai: Incorrect calculations of clipping boundaries
  • eb8db12: 8263396: Atomic::CmpxchgByteUsingInt::set_byte_in_int needs an explicit cast
  • ... and 62 more: https://git.openjdk.java.net/jdk/compare/75a2354dc276e107d64516d20fc72bc7ef3d5f86...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@kevinjwalls, @Hamlin-Li, @AlanBateman) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

Loading

@openjdk openjdk bot added the ready label Apr 30, 2021
@kevinjwalls
Copy link

@kevinjwalls kevinjwalls commented Apr 30, 2021

Oops - please update the copyright year, thanks! (second year in the header is currently 2019, should become 2021).

Loading

@Wanghuang-Huawei
Copy link
Author

@Wanghuang-Huawei Wanghuang-Huawei commented May 1, 2021

Oops - please update the copyright year, thanks! (second year in the header is currently 2019, should become 2021).

Thank you for your suggestion. I have update that.

Loading

@Wanghuang-Huawei
Copy link
Author

@Wanghuang-Huawei Wanghuang-Huawei commented May 1, 2021

/integrate

Loading

@openjdk openjdk bot added the sponsor label May 1, 2021
@openjdk
Copy link

@openjdk openjdk bot commented May 1, 2021

@Wanghuang-Huawei
Your change (at version c289957) is now ready to be sponsored by a Committer.

Loading

@kevinjwalls
Copy link

@kevinjwalls kevinjwalls commented May 4, 2021

/sponsor

Loading

@openjdk openjdk bot closed this May 4, 2021
@openjdk
Copy link

@openjdk openjdk bot commented May 4, 2021

@kevinjwalls @Wanghuang-Huawei Since your change was applied there have been 97 commits pushed to the master branch:

  • b651904: 8266438: Compile::remove_useless_nodes does not remove opaque nodes
  • 141cc2f: 8261527: Record page size used for underlying mapping in ReservedSpace
  • 8e071c4: 8265784: [C2] Hoisting of DecodeN leaves MachTemp inputs behind
  • ce1bc9d: 8266432: ZGC: GC allocation stalls can trigger deadlocks
  • 30ccd80: 8264950: Set opaque for JTooltip in config file of NimbusLookAndFeel
  • cfdf4a7: 8266449: cleanup jtreg tags in compiler/intrinsics/sha/cli tests
  • 3544a9d: 8266391: Replace use of reflection in jdk.internal.platform.Metrics
  • 020236c: 8264786: [macos] All Swing/AWT apps cause Allow Notifications prompt to appear when app is launched
  • 45760d4: 8266320: (bf) ReadOnlyBufferException in heap buffer put(String,int,int) should not be conditional
  • ff65920: 8265491: Math Signum optimization for x86
  • ... and 87 more: https://git.openjdk.java.net/jdk/compare/75a2354dc276e107d64516d20fc72bc7ef3d5f86...master

Your commit was automatically rebased without conflicts.

Pushed as commit aa90df6.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants