[Goodies-dev] [Bug 15196] New: [patch] remove unnecessary strdup

bugzilla-daemon at xfce.org bugzilla-daemon at xfce.org
Thu Mar 14 20:57:29 CET 2019


https://bugzilla.xfce.org/show_bug.cgi?id=15196

            Bug ID: 15196
           Summary: [patch] remove unnecessary strdup
    Classification: Panel Plugins
           Product: Xfce4-battery-plugin
           Version: git
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: Medium
         Component: General
          Assignee: goodies-dev at xfce.org
          Reporter: ivan.middleton at gmail.com
  Target Milestone: ---

Here's a quick patch for an unnecessary string duplication I found in
battery.c:

--- panel-plugin/battery.c                                         
+++ panel-plugin/battery.c                                         
@@ -296,8 +296,7 @@
         }

         if (acline && new_state != BM_MISSING) {
-            gchar *tmp = g_strdup(icon_name);
-            g_free(icon_name);
+            gchar *tmp = icon_name;
             new_state++;
             icon_name = g_strconcat(tmp, "-charging", NULL);
             g_free(tmp);

I found this because I noticed a memory leak in this code, which has already
been fixed in the following commit:

https://git.xfce.org/panel-plugins/xfce4-battery-plugin/commit/panel-plugin/battery.c?id=b32c015ed36c0f6e9e053351482303a15615847a

It's not necessary to duplicate the original string. One only needs a copy of
the pointer to it, so that it can be freed after its pointer is adjusted.

-- 
You are receiving this mail because:
You are the assignee for the bug.


More information about the Goodies-dev mailing list