Skip to content

Commit

Permalink
Fix memory leak by pGbytes
Browse files Browse the repository at this point in the history
  • Loading branch information
1579272094 committed Nov 14, 2019
1 parent 2b70e92 commit 88ac421
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,14 +354,18 @@ GVariant *Utils::gvariantFromByteArray(const std::string &str)
GVariant *Utils::gvariantFromByteArray(const guint8 *pBytes, int count)
{
GBytes *pGbytes = g_bytes_new(pBytes, count);
return g_variant_new_from_bytes(G_VARIANT_TYPE_BYTESTRING, pGbytes, count);
GVariant *pGVariant = g_variant_new_from_bytes(G_VARIANT_TYPE_BYTESTRING, pGbytes, count);
g_bytes_unref(pGbytes);
return pGVariant;
}

// Returns an array of bytes ("ay") with the contents of the input array of unsigned 8-bit values
GVariant *Utils::gvariantFromByteArray(const std::vector<guint8> bytes)
{
GBytes *pGbytes = g_bytes_new(bytes.data(), bytes.size());
return g_variant_new_from_bytes(G_VARIANT_TYPE_BYTESTRING, pGbytes, bytes.size());
GVariant *pGVariant = g_variant_new_from_bytes(G_VARIANT_TYPE_BYTESTRING, pGbytes, bytes.size());
g_bytes_unref(pGbytes);
return pGVariant;
}

// Returns an array of bytes ("ay") containing a single unsigned 8-bit value
Expand Down Expand Up @@ -422,4 +426,4 @@ std::string Utils::stringFromGVariantByteArray(const GVariant *pVariant)
return array.data();
}

}; // namespace ggk
}; // namespace ggk

0 comments on commit 88ac421

Please sign in to comment.