fix memory leaks on error; found by brainy.

This commit is contained in:
christos 2015-07-04 22:39:23 +00:00
parent eeda512b55
commit a6e4c202c0
1 changed files with 15 additions and 18 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: lua-bozo.c,v 1.11 2014/08/15 19:35:28 mbalmer Exp $ */
/* $NetBSD: lua-bozo.c,v 1.12 2015/07/04 22:39:23 christos Exp $ */
/*
* Copyright (c) 2013 Marc Balmer <marc@msys.ch>
@ -311,41 +311,38 @@ bozo_process_lua(bozo_httpreq_t *request)
if (!httpd->process_lua)
return 0;
info = NULL;
query = NULL;
prefix = NULL;
uri = request->hr_oldfile ? request->hr_oldfile : request->hr_file;
if (*uri == '/') {
file = bozostrdup(httpd, uri);
if (file == NULL)
goto out;
prefix = bozostrdup(httpd, &uri[1]);
} else {
if (asprintf(&file, "/%s", uri) < 0)
goto out;
prefix = bozostrdup(httpd, uri);
asprintf(&file, "/%s", uri);
}
if (file == NULL) {
free(prefix);
return 0;
}
if (prefix == NULL)
goto out;
if (request->hr_query && strlen(request->hr_query))
if (request->hr_query && request->hr_query[0])
query = bozostrdup(httpd, request->hr_query);
else
query = NULL;
p = strchr(prefix, '/');
if (p == NULL){
free(prefix);
return 0;
}
if (p == NULL)
goto out;
*p++ = '\0';
handler = p;
if (!*handler) {
free(prefix);
return 0;
}
if (!*handler)
goto out;
p = strchr(handler, '/');
if (p != NULL)
*p++ = '\0';
info = NULL;
command = file + 1;
if ((s = strchr(command, '/')) != NULL) {
info = bozostrdup(httpd, s);