[BugFix] Fix NPE for JoinHashTable::mem_usage (backport #61872) (#61915)

Signed-off-by: zihe.liu <ziheliu1024@gmail.com>
Co-authored-by: zihe.liu <ziheliu1024@gmail.com>
This commit is contained in:
mergify[bot] 2025-08-14 03:20:04 +00:00 committed by GitHub
parent 1cf54d7670
commit 6bebdbac4d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 0 deletions

View File

@ -26,6 +26,7 @@
#include "simd/simd.h"
#include "types/logical_type_infra.h"
#include "util/runtime_profile.h"
#include "util/stack_util.h"
namespace starrocks {
@ -483,6 +484,15 @@ void JoinHashTable::_init_join_keys() {
}
int64_t JoinHashTable::mem_usage() const {
// Theoretically, `_table_items` may be a nullptr after a cancel, even though in practice we havent observed any
// cases where `_table_items` was unexpectedly cleared or left uninitialized.
// To prevent potential null pointer exceptions, we add a defensive check here.
if (_table_items == nullptr) {
LOG(WARNING) << "table_items is nullptr in mem_usage, stack:" << get_stack_trace();
DCHECK(false);
return 0;
}
int64_t usage = 0;
if (_table_items->build_chunk != nullptr) {
usage += _table_items->build_chunk->memory_usage();