Fix leak in print_one_catch_syscall.
authorPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Mon, 31 Dec 2018 17:07:26 +0000 (18:07 +0100)
committerPhilippe Waroquiers <philippe.waroquiers@skynet.be>
Tue, 1 Jan 2019 19:26:18 +0000 (20:26 +0100)
The last text produced was not freed, causing the below leak
(e.g. in gdb.base/catch-syscall.exp):

==24970== 56 bytes in 12 blocks are definitely lost in loss record 626 of 3,289
==24970==    at 0x4C2BE6D: malloc (vg_replace_malloc.c:309)
==24970==    by 0x66B9C3F: __vasprintf_chk (vasprintf_chk.c:80)
==24970==    by 0x405181: vasprintf (stdio2.h:210)
==24970==    by 0x405181: xstrvprintf(char const*, __va_list_tag*) (common-utils.c:122)
==24970==    by 0x40524B: xstrprintf(char const*, ...) (common-utils.c:113)
==24970==    by 0x3B49DB: print_one_catch_syscall(breakpoint*, bp_location**) (break-catch-syscall.c:275)
==24970==    by 0x3C698F: print_one_breakpoint_location(breakpoint*, bp_location*, int, bp_location**, int) (breakpoint.c:6076)
==24970==    by 0x3C75B1: print_one_breakpoint(breakpoint*, bp_location**, int) (breakpoint.c:6373)
==24970==    by 0x3C7D0E: breakpoint_1(char const*, int, int (*)(breakpoint const*)) (breakpoint.c:6571)
==24970==    by 0x3C822C: info_breakpoints_command(char const*, int) (breakpoint.c:6625)

2019-01-01  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

* break-catch-syscall.c (print_one_catch_syscall): xfree
the last text.

gdb/ChangeLog
gdb/break-catch-syscall.c

index a2f6aacb267a64f2f265cbee991f1855b0223b79..2402d7358756c247060d52d7ca6c50cc7c5be417 100644 (file)
@@ -1,3 +1,8 @@
+2019-01-01  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
+
+       * break-catch-syscall.c (print_one_catch_syscall): xfree
+       the last text.
+
 2019-01-01  Joel Brobecker  <brobecker@adacore.com>
 
        * top.c (print_gdb_version): Update Copyright year in version
index 33018ec99c2450c322af40f7743232c3b67c070f..6a911fbc2a3aa470adbe3ab25b633c670d79778b 100644 (file)
@@ -265,7 +265,7 @@ print_one_catch_syscall (struct breakpoint *b,
 
       for (int iter : c->syscalls_to_be_caught)
         {
-          char *x = text;
+          char *previous_text = text;
           struct syscall s;
           get_syscall_by_number (gdbarch, iter, &s);
 
@@ -274,14 +274,15 @@ print_one_catch_syscall (struct breakpoint *b,
           else
             text = xstrprintf ("%s%d, ", text, iter);
 
-          /* We have to xfree the last 'text' (now stored at 'x')
-             because xstrprintf dynamically allocates new space for it
-             on every call.  */
-         xfree (x);
+          /* We have to xfree previous_text because xstrprintf dynamically
+            allocates new space for text on every call.  */
+         xfree (previous_text);
         }
       /* Remove the last comma.  */
       text[strlen (text) - 2] = '\0';
       uiout->field_string ("what", text);
+      /* xfree last text.  */
+      xfree (text);
     }
   else
     uiout->field_string ("what", "<any syscall>");
This page took 0.041191 seconds and 4 git commands to generate.