src/os/aix/vm/os_aix.cpp
Print this page
rev 6139 : 8038201: Clean up misleading usage of malloc() in init_system_properties_values()
Summary: Add missing freeing of memory or use local variable. Also add a 'const' to avoid gcc write-string warnings on ppc.
*** 376,392 ****
// This really would surprise me.
assert(_page_size == SIZE_4K, "surprise!");
! // query default data page size (default page size for C-Heap, pthread stacks and .bss).
// Default data page size is influenced either by linker options (-bdatapsize)
// or by environment variable LDR_CNTRL (suboption DATAPSIZE). If none is given,
// default should be 4K.
size_t data_page_size = SIZE_4K;
{
void* p = ::malloc(SIZE_16M);
data_page_size = os::Aix::query_pagesize(p);
::free(p);
}
// query default shm page size (LDR_CNTRL SHMPSIZE)
--- 376,393 ----
// This really would surprise me.
assert(_page_size == SIZE_4K, "surprise!");
! // Query default data page size (default page size for C-Heap, pthread stacks and .bss).
// Default data page size is influenced either by linker options (-bdatapsize)
// or by environment variable LDR_CNTRL (suboption DATAPSIZE). If none is given,
// default should be 4K.
size_t data_page_size = SIZE_4K;
{
void* p = ::malloc(SIZE_16M);
+ guarantee(p != NULL, "malloc failed");
data_page_size = os::Aix::query_pagesize(p);
::free(p);
}
// query default shm page size (LDR_CNTRL SHMPSIZE)
*** 509,597 ****
fprintf(stderr, "Multipage error details: %d\n", g_multipage_error);
}
} // end os::Aix::query_multipage_support()
!
! // The code for this method was initially derived from the version in os_linux.cpp
void os::init_system_properties_values() {
! // The next few definitions allow the code to be verbatim:
! #define malloc(n) (char*)NEW_C_HEAP_ARRAY(char, (n), mtInternal)
#define DEFAULT_LIBPATH "/usr/lib:/lib"
#define EXTENSIONS_DIR "/lib/ext"
#define ENDORSED_DIR "/lib/endorsed"
// sysclasspath, java_home, dll_dir
! char *home_path;
! char *dll_path;
char *pslash;
char buf[MAXPATHLEN];
os::jvm_path(buf, sizeof(buf));
// Found the full path to libjvm.so.
// Now cut the path to <java_home>/jre if we can.
! *(strrchr(buf, '/')) = '\0'; // get rid of /libjvm.so
pslash = strrchr(buf, '/');
if (pslash != NULL) {
! *pslash = '\0'; // get rid of /{client|server|hotspot}
}
!
! dll_path = malloc(strlen(buf) + 1);
! strcpy(dll_path, buf);
! Arguments::set_dll_dir(dll_path);
if (pslash != NULL) {
pslash = strrchr(buf, '/');
if (pslash != NULL) {
! *pslash = '\0'; // get rid of /<arch>
pslash = strrchr(buf, '/');
if (pslash != NULL) {
! *pslash = '\0'; // get rid of /lib
}
}
}
! home_path = malloc(strlen(buf) + 1);
! strcpy(home_path, buf);
! Arguments::set_java_home(home_path);
!
! if (!set_boot_path('/', ':')) return;
! // Where to look for native libraries
! // On Aix we get the user setting of LIBPATH
// Eventually, all the library path setting will be done here.
! char *ld_library_path;
!
! // Construct the invariant part of ld_library_path.
! ld_library_path = (char *) malloc(sizeof(DEFAULT_LIBPATH));
! sprintf(ld_library_path, DEFAULT_LIBPATH);
!
! // Get the user setting of LIBPATH, and prepended it.
char *v = ::getenv("LIBPATH");
if (v == NULL) {
v = "";
}
! char *t = ld_library_path;
! // That's +1 for the colon and +1 for the trailing '\0'
! ld_library_path = (char *) malloc(strlen(v) + 1 + strlen(t) + 1);
! sprintf(ld_library_path, "%s:%s", v, t);
!
Arguments::set_library_path(ld_library_path);
! // Extensions directories
! char* cbuf = malloc(strlen(Arguments::get_java_home()) + sizeof(EXTENSIONS_DIR));
! sprintf(cbuf, "%s" EXTENSIONS_DIR, Arguments::get_java_home());
! Arguments::set_ext_dirs(cbuf);
// Endorsed standards default directory.
! cbuf = malloc(strlen(Arguments::get_java_home()) + sizeof(ENDORSED_DIR));
! sprintf(cbuf, "%s" ENDORSED_DIR, Arguments::get_java_home());
! Arguments::set_endorsed_dirs(cbuf);
- #undef malloc
#undef DEFAULT_LIBPATH
#undef EXTENSIONS_DIR
#undef ENDORSED_DIR
}
--- 510,589 ----
fprintf(stderr, "Multipage error details: %d\n", g_multipage_error);
}
} // end os::Aix::query_multipage_support()
! // The code for this method was initially derived from the version in os_linux.cpp.
void os::init_system_properties_values() {
!
#define DEFAULT_LIBPATH "/usr/lib:/lib"
#define EXTENSIONS_DIR "/lib/ext"
#define ENDORSED_DIR "/lib/endorsed"
// sysclasspath, java_home, dll_dir
! {
char *pslash;
char buf[MAXPATHLEN];
os::jvm_path(buf, sizeof(buf));
// Found the full path to libjvm.so.
// Now cut the path to <java_home>/jre if we can.
! *(strrchr(buf, '/')) = '\0'; // Get rid of /libjvm.so.
pslash = strrchr(buf, '/');
if (pslash != NULL) {
! *pslash = '\0'; // Get rid of /{client|server|hotspot}.
}
! Arguments::set_dll_dir(buf);
if (pslash != NULL) {
pslash = strrchr(buf, '/');
if (pslash != NULL) {
! *pslash = '\0'; // Get rid of /<arch>.
pslash = strrchr(buf, '/');
if (pslash != NULL) {
! *pslash = '\0'; // Get rid of /lib.
}
}
}
+ Arguments::set_java_home(buf);
! if (!set_boot_path('/', ':')) {
! return;
! }
! }
! // Where to look for native libraries.
! // On Aix we get the user setting of LIBPATH.
// Eventually, all the library path setting will be done here.
! // Get the user setting of LIBPATH.
char *v = ::getenv("LIBPATH");
if (v == NULL) {
v = "";
}
! // Concatenate user and invariant part of ld_library_path.
! // That's +1 for the colon and +1 for the trailing '\0'.
! char *ld_library_path = (char *)NEW_C_HEAP_ARRAY(char, strlen(v) + 1 + sizeof(DEFAULT_LIBPATH) + 1, mtInternal);
! sprintf(ld_library_path, "%s:%s", v, DEFAULT_LIBPATH);
Arguments::set_library_path(ld_library_path);
+ FREE_C_HEAP_ARRAY(char, ld_library_path, mtInternal);
! // Buffer that fits both sprintfs.
! // Note that the space for the colon and the trailing null are provided
! // by the nulls included by the sizeof operator (so actually one byte more
! // than necessary is allocated).
! char buf[MAXPATHLEN + sizeof(EXTENSIONS_DIR) + sizeof(ENDORSED_DIR)];
!
! // Extensions directories.
! sprintf(buf, "%s" EXTENSIONS_DIR, Arguments::get_java_home());
! Arguments::set_ext_dirs(buf);
// Endorsed standards default directory.
! sprintf(buf, "%s" ENDORSED_DIR, Arguments::get_java_home());
! Arguments::set_endorsed_dirs(buf);
#undef DEFAULT_LIBPATH
#undef EXTENSIONS_DIR
#undef ENDORSED_DIR
}