Browse Source

Fix a memory leak in CarlaString class

Signed-off-by: falkTX <falktx@falktx.com>
tags/v2.3.2
falkTX 3 years ago
parent
commit
06c8bf8c33
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
1 changed files with 13 additions and 4 deletions
  1. +13
    -4
      source/utils/CarlaString.hpp

+ 13
- 4
source/utils/CarlaString.hpp View File

@@ -58,12 +58,21 @@ public:
/* /*
* Simple char string. * Simple char string.
*/ */
explicit CarlaString(char* const strBuf) noexcept
explicit CarlaString(char* const strBuf, const bool reallocData = true) noexcept
: fBuffer(_null()), : fBuffer(_null()),
fBufferLen(0), fBufferLen(0),
fBufferAlloc(false) fBufferAlloc(false)
{ {
_dup(strBuf);
if (reallocData || strBuf == nullptr)
{
_dup(strBuf);
}
else
{
fBuffer = strBuf;
fBufferLen = std::strlen(strBuf);
fBufferAlloc = true;
}
} }


/* /*
@@ -909,7 +918,7 @@ CarlaString operator+(const CarlaString& strBefore, const char* const strBufAfte
std::memcpy(newBuf, strBefore.buffer(), strBeforeLen); std::memcpy(newBuf, strBefore.buffer(), strBeforeLen);
std::memcpy(newBuf + strBeforeLen, strBufAfter, strBufAfterLen + 1); std::memcpy(newBuf + strBeforeLen, strBufAfter, strBufAfterLen + 1);


return CarlaString(newBuf);
return CarlaString(newBuf, false);
} }


static inline static inline
@@ -929,7 +938,7 @@ CarlaString operator+(const char* const strBufBefore, const CarlaString& strAfte
std::memcpy(newBuf, strBufBefore, strBufBeforeLen); std::memcpy(newBuf, strBufBefore, strBufBeforeLen);
std::memcpy(newBuf + strBufBeforeLen, strAfter.buffer(), strAfterLen + 1); std::memcpy(newBuf + strBufBeforeLen, strAfter.buffer(), strAfterLen + 1);


return CarlaString(newBuf);
return CarlaString(newBuf, false);
} }


// ----------------------------------------------------------------------- // -----------------------------------------------------------------------


Loading…
Cancel
Save