Make every java process 20 bytes smaller
Martin Buchholz
martinrb at google.com
Sun Jun 14 17:08:48 UTC 2009
Hello Kumar,
I'd like you to do a code review and file a bug.
Synopsis: Fix small memory leak in launcher
Description:
This little change to the launcher
- fixes a leak of 20 bytes in *every* java process
- fixes the leak of classpath wildcard expansion
when that feature is used.
diff --git a/src/share/bin/java.c b/src/share/bin/java.c
--- a/src/share/bin/java.c
+++ b/src/share/bin/java.c
@@ -683,10 +683,14 @@
SetClassPath(const char *s)
{
char *def;
+ const char *orig = s;
+ static const char format[] = "-Djava.class.path=%s";
s = JLI_WildcardExpandClasspath(s);
- def = JLI_MemAlloc(JLI_StrLen(s) + 40);
- sprintf(def, "-Djava.class.path=%s", s);
+ def = JLI_MemAlloc(sizeof(format) - 2 + JLI_StrLen(s));
+ sprintf(def, format, s);
AddOption(def, NULL);
+ if (s != orig)
+ JLI_MemFree((char *) s);
}
/*
This code is particularly prone to off-by-one bugs,
but I think we can get it right.
Webrev at:
http://cr.openjdk.java.net/~martin/launcher-leak/
Is Kowalski still around? He may have been the last person to touch this.
Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/core-libs-dev/attachments/20090614/60a65780/attachment.html>
More information about the core-libs-dev
mailing list