Why not this instead? Also fix some other similar problems.

Index: cmd-load-buffer.c
===================================================================
RCS file: /cvs/src/usr.bin/tmux/cmd-load-buffer.c,v
retrieving revision 1.25
diff -u -p -r1.25 cmd-load-buffer.c
--- cmd-load-buffer.c   10 Oct 2013 12:26:35 -0000      1.25
+++ cmd-load-buffer.c   14 Feb 2014 12:32:44 -0000
@@ -169,6 +169,7 @@ cmd_load_buffer_callback(struct client *
                /* No context so can't use server_client_msg_error. */
                evbuffer_add_printf(c->stderr_data, "no buffer %d\n", *buffer);
                server_push_stderr(c);
+               free(pdata);
        }
 
        free(data);
Index: paste.c
===================================================================
RCS file: /cvs/src/usr.bin/tmux/paste.c,v
retrieving revision 1.14
diff -u -p -r1.14 paste.c
--- paste.c     27 Nov 2012 20:22:12 -0000      1.14
+++ paste.c     14 Feb 2014 12:32:19 -0000
@@ -131,8 +131,10 @@ paste_replace(struct paste_stack *ps, u_
 {
        struct paste_buffer     *pb;
 
-       if (size == 0)
+       if (size == 0) {
+               free(data);
                return (0);
+       }
 
        if (idx >= ARRAY_LENGTH(ps))
                return (-1);
Index: window-copy.c
===================================================================
RCS file: /cvs/src/usr.bin/tmux/window-copy.c,v
retrieving revision 1.101
diff -u -p -r1.101 window-copy.c
--- window-copy.c       28 Jan 2014 23:07:09 -0000      1.101
+++ window-copy.c       14 Feb 2014 12:33:06 -0000
@@ -1455,8 +1455,8 @@ window_copy_copy_buffer(struct window_pa
        if (idx == -1) {
                limit = options_get_number(&global_options, "buffer-limit");
                paste_add(&global_buffers, buf, len, limit);
-       } else
-               paste_replace(&global_buffers, idx, buf, len);
+       } else if (paste_replace(&global_buffers, idx, buf, len) != 0)
+               free(buf);
 }
 
 void



On Fri, Feb 14, 2014 at 01:29:57AM -0600, J Raynor wrote:
> It looks like there's a potential memory leak in
> window_copy_copy_selection.  This function calls
> window_copy_copy_buffer, which calls paste_replace.  If paste_replace
> succeeds, it stores the data that was passed to it.
> 
> But if paste_replace fails, such as when an invalid buffer index is
> specified, it doesn't store the data, and nothing frees the memory
> that was allocated.
> 
> window_copy_copy_pipe has the same problem.
> 
> I've attached a patch which should fix this.


> ------------------------------------------------------------------------------
> Android apps run on BlackBerry 10
> Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
> Now with support for Jelly Bean, Bluetooth, Mapview and more.
> Get your Android app in front of a whole new audience.  Start now.
> http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk

> _______________________________________________
> tmux-users mailing list
> tmux-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/tmux-users


------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to