After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 760022 - Memory leak in gvariant-parser.c
Memory leak in gvariant-parser.c
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gvariant
2.46.x
Other Linux
: Normal major
: ---
Assigned To: Allison Karlitskaya (desrt)
gtkdev
: 777076 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2015-12-31 08:25 UTC by Sanjeev
Modified: 2017-11-08 12:38 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Memory leak fix (691 bytes, patch)
2015-12-31 08:25 UTC, Sanjeev
committed Details | Review

Description Sanjeev 2015-12-31 08:25:49 UTC
Created attachment 318060 [details] [review]
Memory leak fix

In File gvariant-parser.c "bytestring_parse" function memory is assigned to gchar pointer variable str as below
str = g_malloc (length);
but in switch cases while returning NULL. str variable is going out of scope and memory assigned to str is not freed.

Code modification is as Below :

Before :

str = g_malloc (length);
.....
while (token[i] != quote)

    switch (token[i])
{
      case '\0':
        parser_set_error (error, &ref, NULL,
                          G_VARIANT_PARSE_ERROR_UNTERMINATED_STRING_CONSTANT,
                          "unterminated string constant");

        g_free (token);
        ....

After :

str = g_malloc (length);

…....
 while (token[i] != quote)
switch (token[i])
{
case '\0':

    parser_set_error (error, &ref, NULL,
                          G_VARIANT_PARSE_ERROR_UNTERMINATED_STRING_CONSTANT,
                         "unterminated string constant");

        g_free (token);
        g_free (str);
        return NULL;
Comment 1 Philip Withnall 2017-11-08 12:26:57 UTC
*** Bug 777076 has been marked as a duplicate of this bug. ***
Comment 2 Philip Withnall 2017-11-08 12:37:40 UTC
Comment on attachment 318060 [details] [review]
Memory leak fix

This looks correct to me. Thanks for the patch, and sorry for the delay in reviewing and applying it.

I’ll add a commit message to it before pushing. In future, please provide git-formatted patches (`git format-patch -1`).