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..
This commit is contained in:
parent
12d8621dac
commit
b0f74aaafd
@ -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 @@ bozo_set_pref(bozohttpd_t *httpd, bozoprefs_t *bozoprefs,
|
||||
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 @@ bozo_clean_request(bozo_httpreq_t *request)
|
||||
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 @@ bozo_setup(bozohttpd_t *httpd, bozoprefs_t *prefs, const char *vhost,
|
||||
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)
|
||||
{
|
||||
|
@ -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_httpd(bozohttpd_t *);
|
||||
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 *);
|
||||
|
@ -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 @@ and queried using the two
|
||||
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 ,
|
||||
|
@ -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 @@ main(int argc, char **argv)
|
||||
}
|
||||
} while (httpd.background);
|
||||
|
||||
bozo_cleanup(&httpd, &prefs);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user