Skip to content

Commit ec833e2

Browse files
committed
Fix memory leaks in Component::GetGuid/GetName/GetDisplayName
1 parent bac52f4 commit ec833e2

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

component.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,19 @@ Component::Component(BNComponent* component)
2525

2626
std::string Component::GetDisplayName()
2727
{
28-
return BNComponentGetDisplayName(m_object);
28+
char* result = BNComponentGetDisplayName(m_object);
29+
string stringResult = result;
30+
BNFreeString(result);
31+
return stringResult;
2932
}
3033

3134

3235
std::string Component::GetName()
3336
{
34-
return BNComponentGetOriginalName(m_object);
37+
char* result = BNComponentGetOriginalName(m_object);
38+
string stringResult = result;
39+
BNFreeString(result);
40+
return stringResult;
3541
}
3642

3743

@@ -55,7 +61,10 @@ Ref<Component> Component::GetParent()
5561

5662
std::string Component::GetGuid()
5763
{
58-
return string(BNComponentGetGuid(m_object));
64+
char* result = BNComponentGetGuid(m_object);
65+
string stringResult = result;
66+
BNFreeString(result);
67+
return stringResult;
5968
}
6069

6170

0 commit comments

Comments
 (0)