Skip to content

Commit

Permalink
8322057: Memory leaks in creating jfr symbol array
Browse files Browse the repository at this point in the history
Reviewed-by: mgronlun
  • Loading branch information
zhengyu123 committed Dec 14, 2023
1 parent 692be57 commit a7dde57
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/hotspot/share/jfr/jni/jfrJavaSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,12 @@ const char* JfrJavaSupport::c_str(jstring string, Thread* thread, bool c_heap /*
return string != nullptr ? c_str(resolve_non_null(string), thread, c_heap) : nullptr;
}

void JfrJavaSupport::free_c_str(const char* str, bool c_heap) {
if (c_heap) {
FREE_C_HEAP_ARRAY(char, str);
}
}

static Symbol** allocate_symbol_array(bool c_heap, int length, Thread* thread) {
return c_heap ?
NEW_C_HEAP_ARRAY(Symbol*, length, mtTracing) :
Expand All @@ -546,6 +552,7 @@ Symbol** JfrJavaSupport::symbol_array(jobjectArray string_array, JavaThread* thr
if (object != nullptr) {
const char* text = c_str(arrayOop->obj_at(i), thread, c_heap);
symbol = SymbolTable::new_symbol(text);
free_c_str(text, c_heap);
}
result_array[i] = symbol;
}
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/jfr/jni/jfrJavaSupport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class JfrJavaSupport : public AllStatic {
static Klass* klass(const jobject handle);
static const char* c_str(jstring string, Thread* thread, bool c_heap = false);
static const char* c_str(oop string, Thread* thread, bool c_heap = false);
static void free_c_str(const char* str, bool c_heap);
static Symbol** symbol_array(jobjectArray string_array, JavaThread* thread, intptr_t* result_size, bool c_heap = false);

// exceptions
Expand Down

1 comment on commit a7dde57

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.