Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/libexec/httpd fix memory leaks on error; found by brainy.



details:   https://anonhg.NetBSD.org/src/rev/5c3990d531ab
branches:  trunk
changeset: 339206:5c3990d531ab
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Jul 04 22:39:23 2015 +0000

description:
fix memory leaks on error; found by brainy.

diffstat:

 libexec/httpd/lua-bozo.c |  33 +++++++++++++++------------------
 1 files changed, 15 insertions(+), 18 deletions(-)

diffs (65 lines):

diff -r 6f5bc3f9aee1 -r 5c3990d531ab libexec/httpd/lua-bozo.c
--- a/libexec/httpd/lua-bozo.c  Sat Jul 04 15:09:49 2015 +0000
+++ b/libexec/httpd/lua-bozo.c  Sat Jul 04 22:39:23 2015 +0000
@@ -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@localhost>
@@ -311,41 +311,38 @@
        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);



Home | Main Index | Thread Index | Old Index