From 44ed06802472a5d1eeb1fe6db9669543221ce7cb Mon Sep 17 00:00:00 2001 From: reyk Date: Thu, 24 Jul 2014 08:32:36 +0000 Subject: [PATCH] Plug a memleak by correctly free'ing the HTTP descriptor that contains all the headers etc. of a connection. --- usr.sbin/httpd/httpd.c | 4 +--- usr.sbin/httpd/server.c | 7 +++++-- usr.sbin/httpd/server_http.c | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/usr.sbin/httpd/httpd.c b/usr.sbin/httpd/httpd.c index c87c2ad847e..d38b4d9e41c 100644 --- a/usr.sbin/httpd/httpd.c +++ b/usr.sbin/httpd/httpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: httpd.c,v 1.6 2014/07/23 23:10:27 reyk Exp $ */ +/* $OpenBSD: httpd.c,v 1.7 2014/07/24 08:32:36 reyk Exp $ */ /* * Copyright (c) 2014 Reyk Floeter @@ -720,8 +720,6 @@ kv_purge(struct kvtree *keys) void kv_free(struct kv *kv) { - if (kv->kv_type == KEY_TYPE_NONE) - return; if (kv->kv_key != NULL) { free(kv->kv_key); } diff --git a/usr.sbin/httpd/server.c b/usr.sbin/httpd/server.c index 38151ead061..913dbb51b26 100644 --- a/usr.sbin/httpd/server.c +++ b/usr.sbin/httpd/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.7 2014/07/23 13:26:39 reyk Exp $ */ +/* $OpenBSD: server.c,v 1.8 2014/07/24 08:32:36 reyk Exp $ */ /* * Copyright (c) 2006 - 2014 Reyk Floeter @@ -550,6 +550,9 @@ server_close(struct client *clt, const char *msg) SPLAY_REMOVE(client_tree, &srv->srv_clients, clt); + /* free the HTTP descriptors incl. headers */ + server_close_http(clt); + event_del(&clt->clt_ev); if (clt->clt_bev != NULL) bufferevent_disable(clt->clt_bev, EV_READ|EV_WRITE); @@ -575,7 +578,7 @@ server_close(struct client *clt, const char *msg) if (clt->clt_bev != NULL) bufferevent_free(clt->clt_bev); - else if (clt->clt_output != NULL) + if (clt->clt_output != NULL) evbuffer_free(clt->clt_output); if (clt->clt_file != NULL) diff --git a/usr.sbin/httpd/server_http.c b/usr.sbin/httpd/server_http.c index 6e154563e43..21b4684bbea 100644 --- a/usr.sbin/httpd/server_http.c +++ b/usr.sbin/httpd/server_http.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server_http.c,v 1.10 2014/07/23 21:43:12 reyk Exp $ */ +/* $OpenBSD: server_http.c,v 1.11 2014/07/24 08:32:36 reyk Exp $ */ /* * Copyright (c) 2006 - 2014 Reyk Floeter @@ -110,6 +110,7 @@ server_httpdesc_free(struct http_descriptor *desc) desc->http_version = NULL; } kv_purge(&desc->http_headers); + desc->http_lastheader = NULL; } void -- 2.20.1