- djm@cvs.openbsd.org 2008/06/12 15:19:17
[clientloop.h channels.h clientloop.c channels.c mux.c]
The multiplexing escape char handler commit last night introduced a
small memory leak per session; plug it.
diff --git a/ChangeLog b/ChangeLog
index 12471ba..0aec356 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -108,6 +108,10 @@
We already mark the start of the worm, now also mark the end of the worm
in our random art drawings.
ok djm@
+ - djm@cvs.openbsd.org 2008/06/12 15:19:17
+ [clientloop.h channels.h clientloop.c channels.c mux.c]
+ The multiplexing escape char handler commit last night introduced a
+ small memory leak per session; plug it.
20080611
- (djm) [channels.c configure.ac]
@@ -4270,4 +4274,4 @@
OpenServer 6 and add osr5bigcrypt support so when someone migrates
passwords between UnixWare and OpenServer they will still work. OK dtucker@
-$Id: ChangeLog,v 1.4983 2008/06/12 18:55:10 dtucker Exp $
+$Id: ChangeLog,v 1.4984 2008/06/12 18:55:46 dtucker Exp $
diff --git a/channels.c b/channels.c
index c539990..04cd6b0 100644
--- a/channels.c
+++ b/channels.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: channels.c,v 1.279 2008/06/12 03:40:52 djm Exp $ */
+/* $OpenBSD: channels.c,v 1.280 2008/06/12 15:19:17 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -328,6 +328,8 @@
c->open_confirm_ctx = NULL;
c->input_filter = NULL;
c->output_filter = NULL;
+ c->filter_ctx = NULL;
+ c->filter_cleanup = NULL;
TAILQ_INIT(&c->status_confirms);
debug("channel %d: new [%s]", found, remote_name);
return c;
@@ -416,6 +418,8 @@
bzero(cc, sizeof(*cc));
xfree(cc);
}
+ if (c->filter_cleanup != NULL && c->filter_ctx != NULL)
+ c->filter_cleanup(c->self, c->filter_ctx);
channels[c->self] = NULL;
xfree(c);
}
@@ -731,7 +735,7 @@
void
channel_register_filter(int id, channel_infilter_fn *ifn,
- channel_outfilter_fn *ofn, void *ctx)
+ channel_outfilter_fn *ofn, channel_filter_cleanup_fn *cfn, void *ctx)
{
Channel *c = channel_lookup(id);
@@ -742,6 +746,7 @@
c->input_filter = ifn;
c->output_filter = ofn;
c->filter_ctx = ctx;
+ c->filter_cleanup = cfn;
}
void
diff --git a/channels.h b/channels.h
index 450321d..ec8ea1c 100644
--- a/channels.h
+++ b/channels.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: channels.h,v 1.94 2008/06/12 03:40:52 djm Exp $ */
+/* $OpenBSD: channels.h,v 1.95 2008/06/12 15:19:17 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -62,6 +62,7 @@
typedef void channel_callback_fn(int, void *);
typedef int channel_infilter_fn(struct Channel *, char *, int);
+typedef void channel_filter_cleanup_fn(int, void *);
typedef u_char *channel_outfilter_fn(struct Channel *, u_char **, u_int *);
/* Channel success/failure callbacks */
@@ -132,6 +133,7 @@
channel_infilter_fn *input_filter;
channel_outfilter_fn *output_filter;
void *filter_ctx;
+ channel_filter_cleanup_fn *filter_cleanup;
/* keep boundaries */
int datagram;
@@ -196,7 +198,7 @@
void channel_register_cleanup(int, channel_callback_fn *, int);
void channel_register_open_confirm(int, channel_callback_fn *, void *);
void channel_register_filter(int, channel_infilter_fn *,
- channel_outfilter_fn *, void *);
+ channel_outfilter_fn *, channel_filter_cleanup_fn *, void *);
void channel_register_status_confirm(int, channel_confirm_cb *,
channel_confirm_abandon_cb *, void *);
void channel_cancel_cleanup(int);
diff --git a/clientloop.c b/clientloop.c
index 663daae..d2407ed 100644
--- a/clientloop.c
+++ b/clientloop.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clientloop.c,v 1.197 2008/06/12 04:17:47 djm Exp $ */
+/* $OpenBSD: clientloop.c,v 1.198 2008/06/12 15:19:17 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -1260,6 +1260,13 @@
return (void *)ret;
}
+/* Free the escape filter context on channel free */
+void
+client_filter_cleanup(int cid, void *ctx)
+{
+ xfree(ctx);
+}
+
int
client_simple_escape_filter(Channel *c, char *buf, int len)
{
@@ -1357,6 +1364,7 @@
if (escape_char_arg != SSH_ESCAPECHAR_NONE)
channel_register_filter(session_ident,
client_simple_escape_filter, NULL,
+ client_filter_cleanup,
client_new_escape_filter_ctx(escape_char_arg));
if (session_ident != -1)
channel_register_cleanup(session_ident,
diff --git a/clientloop.h b/clientloop.h
index 3353a9a..8bb874b 100644
--- a/clientloop.h
+++ b/clientloop.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: clientloop.h,v 1.21 2008/06/12 04:06:00 djm Exp $ */
+/* $OpenBSD: clientloop.h,v 1.22 2008/06/12 15:19:17 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -48,6 +48,7 @@
/* Escape filter for protocol 2 sessions */
void *client_new_escape_filter_ctx(int);
+void client_filter_cleanup(int, void *);
int client_simple_escape_filter(Channel *, char *, int);
/* Global request confirmation callbacks */
diff --git a/mux.c b/mux.c
index f5e68f6..8f7bfb7 100644
--- a/mux.c
+++ b/mux.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mux.c,v 1.3 2008/06/12 05:32:30 djm Exp $ */
+/* $OpenBSD: mux.c,v 1.4 2008/06/12 15:19:17 djm Exp $ */
/*
* Copyright (c) 2002-2008 Damien Miller <djm@openbsd.org>
*
@@ -436,6 +436,7 @@
if (cctx->want_tty && escape_char != 0xffffffff) {
channel_register_filter(c->self,
client_simple_escape_filter, NULL,
+ client_filter_cleanup,
client_new_escape_filter_ctx((int)escape_char));
}