Skip to content

Commit 23ec926

Browse files
author
David Holmes
committed
8230395: Code checks for NULL value returned from NEW_C_HEAP_ARRAY which can not happen
Reviewed-by: lkorinth, hseigel, thartmann, dnsimon
1 parent 0e264cf commit 23ec926

File tree

16 files changed

+80
-176
lines changed

16 files changed

+80
-176
lines changed

src/hotspot/os/aix/os_perf_aix.cpp

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,6 @@ CPUPerformanceInterface::CPUPerformance::CPUPerformance() {
445445
bool CPUPerformanceInterface::CPUPerformance::initialize() {
446446
size_t array_entry_count = _counters.nProcs + 1;
447447
_counters.cpus = NEW_C_HEAP_ARRAY(CPUPerfTicks, array_entry_count, mtInternal);
448-
if (NULL == _counters.cpus) {
449-
return false;
450-
}
451448
memset(_counters.cpus, 0, array_entry_count * sizeof(*_counters.cpus));
452449

453450
// For the CPU load total
@@ -535,7 +532,7 @@ CPUPerformanceInterface::CPUPerformanceInterface() {
535532

536533
bool CPUPerformanceInterface::initialize() {
537534
_impl = new CPUPerformanceInterface::CPUPerformance();
538-
return NULL == _impl ? false : _impl->initialize();
535+
return _impl->initialize();
539536
}
540537

541538
CPUPerformanceInterface::~CPUPerformanceInterface() {
@@ -688,19 +685,17 @@ char* SystemProcessInterface::SystemProcesses::ProcessIterator::get_cmdline() {
688685
}
689686
if (size > 0) {
690687
cmdline = NEW_C_HEAP_ARRAY(char, size + 1, mtInternal);
691-
if (cmdline != NULL) {
692-
cmdline[0] = '\0';
693-
if (fseek(fp, 0, SEEK_SET) == 0) {
694-
if (fread(cmdline, 1, size, fp) == size) {
695-
// the file has the arguments separated by '\0',
696-
// so we translate '\0' to ' '
697-
for (size_t i = 0; i < size; i++) {
698-
if (cmdline[i] == '\0') {
699-
cmdline[i] = ' ';
700-
}
688+
cmdline[0] = '\0';
689+
if (fseek(fp, 0, SEEK_SET) == 0) {
690+
if (fread(cmdline, 1, size, fp) == size) {
691+
// the file has the arguments separated by '\0',
692+
// so we translate '\0' to ' '
693+
for (size_t i = 0; i < size; i++) {
694+
if (cmdline[i] == '\0') {
695+
cmdline[i] = ' ';
701696
}
702-
cmdline[size] = '\0';
703697
}
698+
cmdline[size] = '\0';
704699
}
705700
}
706701
}
@@ -790,7 +785,7 @@ SystemProcessInterface::SystemProcesses::SystemProcesses() {
790785

791786
bool SystemProcessInterface::SystemProcesses::initialize() {
792787
_iterator = new SystemProcessInterface::SystemProcesses::ProcessIterator();
793-
return NULL == _iterator ? false : _iterator->initialize();
788+
return _iterator->initialize();
794789
}
795790

796791
SystemProcessInterface::SystemProcesses::~SystemProcesses() {
@@ -837,7 +832,7 @@ SystemProcessInterface::SystemProcessInterface() {
837832

838833
bool SystemProcessInterface::initialize() {
839834
_impl = new SystemProcessInterface::SystemProcesses();
840-
return NULL == _impl ? false : _impl->initialize();
835+
return _impl->initialize();
841836
}
842837

843838
SystemProcessInterface::~SystemProcessInterface() {
@@ -852,15 +847,11 @@ CPUInformationInterface::CPUInformationInterface() {
852847

853848
bool CPUInformationInterface::initialize() {
854849
_cpu_info = new CPUInformation();
855-
if (NULL == _cpu_info) {
856-
return false;
857-
}
858850
_cpu_info->set_number_of_hardware_threads(VM_Version_Ext::number_of_threads());
859851
_cpu_info->set_number_of_cores(VM_Version_Ext::number_of_cores());
860852
_cpu_info->set_number_of_sockets(VM_Version_Ext::number_of_sockets());
861853
_cpu_info->set_cpu_name(VM_Version_Ext::cpu_name());
862854
_cpu_info->set_cpu_description(VM_Version_Ext::cpu_description());
863-
864855
return true;
865856
}
866857

@@ -928,7 +919,7 @@ NetworkPerformanceInterface::~NetworkPerformanceInterface() {
928919

929920
bool NetworkPerformanceInterface::initialize() {
930921
_impl = new NetworkPerformanceInterface::NetworkPerformance();
931-
return _impl != NULL && _impl->initialize();
922+
return _impl->initialize();
932923
}
933924

934925
int NetworkPerformanceInterface::network_utilization(NetworkInterface** network_interfaces) const {

src/hotspot/os/bsd/os_perf_bsd.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -234,7 +234,7 @@ CPUPerformanceInterface::CPUPerformanceInterface() {
234234

235235
bool CPUPerformanceInterface::initialize() {
236236
_impl = new CPUPerformanceInterface::CPUPerformance();
237-
return _impl != NULL && _impl->initialize();
237+
return _impl->initialize();
238238
}
239239

240240
CPUPerformanceInterface::~CPUPerformanceInterface() {
@@ -355,7 +355,7 @@ SystemProcessInterface::SystemProcessInterface() {
355355

356356
bool SystemProcessInterface::initialize() {
357357
_impl = new SystemProcessInterface::SystemProcesses();
358-
return _impl != NULL && _impl->initialize();
358+
return _impl->initialize();
359359
}
360360

361361
SystemProcessInterface::~SystemProcessInterface() {
@@ -370,16 +370,11 @@ CPUInformationInterface::CPUInformationInterface() {
370370

371371
bool CPUInformationInterface::initialize() {
372372
_cpu_info = new CPUInformation();
373-
374-
if (NULL == _cpu_info) {
375-
return false;
376-
}
377373
_cpu_info->set_number_of_hardware_threads(VM_Version_Ext::number_of_threads());
378374
_cpu_info->set_number_of_cores(VM_Version_Ext::number_of_cores());
379375
_cpu_info->set_number_of_sockets(VM_Version_Ext::number_of_sockets());
380376
_cpu_info->set_cpu_name(VM_Version_Ext::cpu_name());
381377
_cpu_info->set_cpu_description(VM_Version_Ext::cpu_description());
382-
383378
return true;
384379
}
385380

@@ -483,7 +478,7 @@ NetworkPerformanceInterface::~NetworkPerformanceInterface() {
483478

484479
bool NetworkPerformanceInterface::initialize() {
485480
_impl = new NetworkPerformanceInterface::NetworkPerformance();
486-
return _impl != NULL && _impl->initialize();
481+
return _impl->initialize();
487482
}
488483

489484
int NetworkPerformanceInterface::network_utilization(NetworkInterface** network_interfaces) const {

src/hotspot/os/linux/os_perf_linux.cpp

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -505,9 +505,6 @@ CPUPerformanceInterface::CPUPerformance::CPUPerformance() {
505505
bool CPUPerformanceInterface::CPUPerformance::initialize() {
506506
size_t array_entry_count = _counters.nProcs + 1;
507507
_counters.cpus = NEW_C_HEAP_ARRAY(os::Linux::CPUPerfTicks, array_entry_count, mtInternal);
508-
if (NULL == _counters.cpus) {
509-
return false;
510-
}
511508
memset(_counters.cpus, 0, array_entry_count * sizeof(*_counters.cpus));
512509

513510
// For the CPU load total
@@ -595,7 +592,7 @@ CPUPerformanceInterface::CPUPerformanceInterface() {
595592

596593
bool CPUPerformanceInterface::initialize() {
597594
_impl = new CPUPerformanceInterface::CPUPerformance();
598-
return NULL == _impl ? false : _impl->initialize();
595+
return _impl->initialize();
599596
}
600597

601598
CPUPerformanceInterface::~CPUPerformanceInterface() {
@@ -748,19 +745,17 @@ char* SystemProcessInterface::SystemProcesses::ProcessIterator::get_cmdline() {
748745
}
749746
if (size > 0) {
750747
cmdline = NEW_C_HEAP_ARRAY(char, size + 1, mtInternal);
751-
if (cmdline != NULL) {
752-
cmdline[0] = '\0';
753-
if (fseek(fp, 0, SEEK_SET) == 0) {
754-
if (fread(cmdline, 1, size, fp) == size) {
755-
// the file has the arguments separated by '\0',
756-
// so we translate '\0' to ' '
757-
for (size_t i = 0; i < size; i++) {
758-
if (cmdline[i] == '\0') {
759-
cmdline[i] = ' ';
760-
}
748+
cmdline[0] = '\0';
749+
if (fseek(fp, 0, SEEK_SET) == 0) {
750+
if (fread(cmdline, 1, size, fp) == size) {
751+
// the file has the arguments separated by '\0',
752+
// so we translate '\0' to ' '
753+
for (size_t i = 0; i < size; i++) {
754+
if (cmdline[i] == '\0') {
755+
cmdline[i] = ' ';
761756
}
762-
cmdline[size] = '\0';
763757
}
758+
cmdline[size] = '\0';
764759
}
765760
}
766761
}
@@ -854,7 +849,7 @@ SystemProcessInterface::SystemProcesses::SystemProcesses() {
854849

855850
bool SystemProcessInterface::SystemProcesses::initialize() {
856851
_iterator = new SystemProcessInterface::SystemProcesses::ProcessIterator();
857-
return NULL == _iterator ? false : _iterator->initialize();
852+
return _iterator->initialize();
858853
}
859854

860855
SystemProcessInterface::SystemProcesses::~SystemProcesses() {
@@ -901,7 +896,7 @@ SystemProcessInterface::SystemProcessInterface() {
901896

902897
bool SystemProcessInterface::initialize() {
903898
_impl = new SystemProcessInterface::SystemProcesses();
904-
return NULL == _impl ? false : _impl->initialize();
899+
return _impl->initialize();
905900
}
906901

907902
SystemProcessInterface::~SystemProcessInterface() {
@@ -916,15 +911,11 @@ CPUInformationInterface::CPUInformationInterface() {
916911

917912
bool CPUInformationInterface::initialize() {
918913
_cpu_info = new CPUInformation();
919-
if (NULL == _cpu_info) {
920-
return false;
921-
}
922914
_cpu_info->set_number_of_hardware_threads(VM_Version_Ext::number_of_threads());
923915
_cpu_info->set_number_of_cores(VM_Version_Ext::number_of_cores());
924916
_cpu_info->set_number_of_sockets(VM_Version_Ext::number_of_sockets());
925917
_cpu_info->set_cpu_name(VM_Version_Ext::cpu_name());
926918
_cpu_info->set_cpu_description(VM_Version_Ext::cpu_description());
927-
928919
return true;
929920
}
930921

@@ -1038,7 +1029,7 @@ NetworkPerformanceInterface::~NetworkPerformanceInterface() {
10381029

10391030
bool NetworkPerformanceInterface::initialize() {
10401031
_impl = new NetworkPerformanceInterface::NetworkPerformance();
1041-
return _impl != NULL && _impl->initialize();
1032+
return _impl->initialize();
10421033
}
10431034

10441035
int NetworkPerformanceInterface::network_utilization(NetworkInterface** network_interfaces) const {

src/hotspot/os/solaris/os_perf_solaris.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,6 @@ bool CPUPerformanceInterface::CPUPerformance::initialize() {
302302
// Data structure(s) for saving CPU load (one per CPU)
303303
size_t array_entry_count = _counters.nProcs;
304304
_counters.jvmTicks = NEW_C_HEAP_ARRAY(CPUPerfTicks, array_entry_count, mtInternal);
305-
if (NULL == _counters.jvmTicks) {
306-
return false;
307-
}
308305
memset(_counters.jvmTicks, 0, array_entry_count * sizeof(*_counters.jvmTicks));
309306

310307
// Get kstat cpu_stat counters for every CPU
@@ -432,7 +429,7 @@ CPUPerformanceInterface::CPUPerformanceInterface() {
432429

433430
bool CPUPerformanceInterface::initialize() {
434431
_impl = new CPUPerformanceInterface::CPUPerformance();
435-
return _impl != NULL && _impl->initialize();
432+
return _impl->initialize();
436433
}
437434

438435
CPUPerformanceInterface::~CPUPerformanceInterface(void) {
@@ -574,10 +571,8 @@ int SystemProcessInterface::SystemProcesses::ProcessIterator::current(SystemProc
574571
if (path_substring != NULL) {
575572
int len = path_substring - psinfo_data.pr_psargs;
576573
exe_path = NEW_C_HEAP_ARRAY(char, len+1, mtInternal);
577-
if (exe_path != NULL) {
578-
jio_snprintf(exe_path, len, "%s", psinfo_data.pr_psargs);
579-
exe_path[len] = '\0';
580-
}
574+
jio_snprintf(exe_path, len, "%s", psinfo_data.pr_psargs);
575+
exe_path[len] = '\0';
581576
}
582577
}
583578

@@ -642,7 +637,7 @@ SystemProcessInterface::SystemProcesses::SystemProcesses() {
642637

643638
bool SystemProcessInterface::SystemProcesses::initialize() {
644639
_iterator = new SystemProcessInterface::SystemProcesses::ProcessIterator();
645-
return _iterator != NULL && _iterator->initialize();
640+
return _iterator->initialize();
646641
}
647642

648643
SystemProcessInterface::SystemProcesses::~SystemProcesses() {
@@ -689,7 +684,7 @@ SystemProcessInterface::SystemProcessInterface() {
689684

690685
bool SystemProcessInterface::initialize() {
691686
_impl = new SystemProcessInterface::SystemProcesses();
692-
return _impl != NULL && _impl->initialize();
687+
return _impl->initialize();
693688

694689
}
695690

@@ -705,9 +700,6 @@ CPUInformationInterface::CPUInformationInterface() {
705700

706701
bool CPUInformationInterface::initialize() {
707702
_cpu_info = new CPUInformation();
708-
if (_cpu_info == NULL) {
709-
return false;
710-
}
711703
_cpu_info->set_number_of_hardware_threads(VM_Version_Ext::number_of_threads());
712704
_cpu_info->set_number_of_cores(VM_Version_Ext::number_of_cores());
713705
_cpu_info->set_number_of_sockets(VM_Version_Ext::number_of_sockets());
@@ -820,7 +812,7 @@ NetworkPerformanceInterface::~NetworkPerformanceInterface() {
820812

821813
bool NetworkPerformanceInterface::initialize() {
822814
_impl = new NetworkPerformanceInterface::NetworkPerformance();
823-
return _impl != NULL && _impl->initialize();
815+
return _impl->initialize();
824816
}
825817

826818
int NetworkPerformanceInterface::network_utilization(NetworkInterface** network_interfaces) const {

0 commit comments

Comments
 (0)