Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/libexec/httpd clean up issues detected by address sanitizer ...
details: https://anonhg.NetBSD.org/src/rev/4964e81234dd
branches: trunk
changeset: 980600:4964e81234dd
user: mrg <mrg%NetBSD.org@localhost>
date: Thu Feb 11 09:57:52 2021 +0000
description:
clean up issues detected by address sanitizer (just some memory
leaks that only apply to the library version.)
XXX: the handling of hr_file and its variants is more crappy
again - the prior clean up is slightly less clean now, but at
least it does not leak memory.
XXX2: cgi-bin test hangs with address sanitizer. don't know
why yet..
diffstat:
libexec/httpd/bozohttpd.c | 36 ++++++++++++++++++++++++++++++-
libexec/httpd/bozohttpd.h | 3 +-
libexec/httpd/libbozohttpd/libbozohttpd.3 | 11 +++++++-
libexec/httpd/main.c | 4 ++-
4 files changed, 49 insertions(+), 5 deletions(-)
diffs (139 lines):
diff -r 45eb5f34e13c -r 4964e81234dd libexec/httpd/bozohttpd.c
--- a/libexec/httpd/bozohttpd.c Thu Feb 11 09:23:55 2021 +0000
+++ b/libexec/httpd/bozohttpd.c Thu Feb 11 09:57:52 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bozohttpd.c,v 1.125 2021/02/11 09:23:55 mrg Exp $ */
+/* $NetBSD: bozohttpd.c,v 1.126 2021/02/11 09:57:52 mrg Exp $ */
/* $eterna: bozohttpd.c,v 1.178 2011/11/18 09:21:15 mrg Exp $ */
@@ -239,6 +239,20 @@
return 1;
}
+static void
+bozo_clear_prefs(bozohttpd_t *httpd, bozoprefs_t *prefs)
+{
+ size_t i;
+
+ for (i = 0; i < prefs->count; i++) {
+ free(prefs->name[i]);
+ free(prefs->value[i]);
+ }
+
+ free(prefs->name);
+ free(prefs->value);
+}
+
/*
* get a variable's value, or NULL
*/
@@ -339,8 +353,11 @@
free(request->hr_serverport);
free(request->hr_virthostname);
free(request->hr_file_free);
+ /* XXX this is gross */
if (request->hr_file_free != request->hr_oldfile)
free(request->hr_oldfile);
+ else
+ free(request->hr_file);
free(request->hr_query);
free(request->hr_host);
bozo_user_free(request->hr_user);
@@ -2694,6 +2711,23 @@
return 1;
}
+void
+bozo_cleanup(bozohttpd_t *httpd, bozoprefs_t *prefs)
+{
+ bozo_clear_prefs(httpd, prefs);
+
+ free(httpd->virthostname);
+ free(httpd->errorbuf);
+ free(httpd->getln_buffer);
+ free(httpd->slashdir);
+#define bozo_unconst(x) ((void *)(uintptr_t)x)
+ free(bozo_unconst(httpd->server_software));
+ free(bozo_unconst(httpd->index_html));
+ free(bozo_unconst(httpd->dir_readme));
+ free(bozo_unconst(httpd->public_html));
+#undef bozo_unconst
+}
+
int
bozo_get_version(char *buf, size_t size)
{
diff -r 45eb5f34e13c -r 4964e81234dd libexec/httpd/bozohttpd.h
--- a/libexec/httpd/bozohttpd.h Thu Feb 11 09:23:55 2021 +0000
+++ b/libexec/httpd/bozohttpd.h Thu Feb 11 09:57:52 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bozohttpd.h,v 1.66 2021/02/11 09:23:55 mrg Exp $ */
+/* $NetBSD: bozohttpd.h,v 1.67 2021/02/11 09:57:52 mrg Exp $ */
/* $eterna: bozohttpd.h,v 1.39 2011/11/18 09:21:15 mrg Exp $ */
@@ -443,6 +443,7 @@
int bozo_init_prefs(bozohttpd_t *, bozoprefs_t *);
int bozo_set_defaults(bozohttpd_t *, bozoprefs_t *);
int bozo_setup(bozohttpd_t *, bozoprefs_t *, const char *, const char *);
+void bozo_cleanup(bozohttpd_t *, bozoprefs_t *);
bozo_httpreq_t *bozo_read_request(bozohttpd_t *);
void bozo_process_request(bozo_httpreq_t *);
void bozo_clean_request(bozo_httpreq_t *);
diff -r 45eb5f34e13c -r 4964e81234dd libexec/httpd/libbozohttpd/libbozohttpd.3
--- a/libexec/httpd/libbozohttpd/libbozohttpd.3 Thu Feb 11 09:23:55 2021 +0000
+++ b/libexec/httpd/libbozohttpd/libbozohttpd.3 Thu Feb 11 09:57:52 2021 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: libbozohttpd.3,v 1.4 2017/02/04 01:32:54 mrg Exp $
+.\" $NetBSD: libbozohttpd.3,v 1.5 2021/02/11 09:57:53 mrg Exp $
.\"
.\" $eterna: libbozohttpd.3,v 1.2 2010/05/10 02:48:23 mrg Exp $
.\"
@@ -29,7 +29,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd February 2, 2017
+.Dd February 11, 2021
.Dt LIBBOZOHTTPD 3
.Os
.Sh NAME
@@ -67,6 +67,10 @@
.Fo bozo_clean_request
.Fa "bozo_httpreq_t *"
.Fc
+.Ft void
+.Fo bozo_cleanup
+.Fa "bozohttpd_t *httpd" "bozoprefs_t *prefs"
+.Fc
.Sh DESCRIPTION
.Nm
is a library interface to the
@@ -124,6 +128,9 @@
function.
This is the main interface for selecting options, and for
setting preferences.
+The memory allocated by
+.Fn bozo_setup
+for both the httpd structure and the preferences will be freed.
.Sh SEE ALSO
.Xr gethostname 3 ,
.Xr ssl 3 ,
diff -r 45eb5f34e13c -r 4964e81234dd libexec/httpd/main.c
--- a/libexec/httpd/main.c Thu Feb 11 09:23:55 2021 +0000
+++ b/libexec/httpd/main.c Thu Feb 11 09:57:52 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.25 2020/10/15 04:21:53 mrg Exp $ */
+/* $NetBSD: main.c,v 1.26 2021/02/11 09:57:52 mrg Exp $ */
/* $eterna: main.c,v 1.6 2011/11/18 09:21:15 mrg Exp $ */
/* from: eterna: bozohttpd.c,v 1.159 2009/05/23 02:14:30 mrg Exp */
@@ -408,5 +408,7 @@
}
} while (httpd.background);
+ bozo_cleanup(&httpd, &prefs);
+
return (0);
}
Home |
Main Index |
Thread Index |
Old Index