]> granicus.if.org Git - libevent/commitdiff
Fix a couple of memory leaks in samples/http-server.c. Found by Dave Hart.
authorNick Mathewson <nickm@torproject.org>
Thu, 14 Apr 2011 18:15:13 +0000 (14:15 -0400)
committerNick Mathewson <nickm@torproject.org>
Thu, 14 Apr 2011 18:17:58 +0000 (14:17 -0400)
sample/http-server.c

index d5212c515a7302564b30cf905ce6232156f24810..05dc165ec8f105b9f37c1d89e8428d2506271e40 100644 (file)
@@ -144,7 +144,7 @@ dump_request_cb(struct evhttp_request *req, void *arg)
 static void
 send_document_cb(struct evhttp_request *req, void *arg)
 {
-       struct evbuffer *evb;
+       struct evbuffer *evb = NULL;
        const char *docroot = arg;
        const char *uri = evhttp_request_get_uri(req);
        struct evhttp_uri *decoded = NULL;
@@ -229,7 +229,6 @@ send_document_cb(struct evhttp_request *req, void *arg)
                if (!(d = opendir(whole_path)))
                        goto err;
 #endif
-               close(fd);
 
                evbuffer_add_printf(evb, "<html>\n <head>\n"
                    "  <title>%s</title>\n"
@@ -286,18 +285,20 @@ send_document_cb(struct evhttp_request *req, void *arg)
        }
 
        evhttp_send_reply(req, 200, "OK", evb);
-       evbuffer_free(evb);
-       return;
+       goto done;
 err:
        evhttp_send_error(req, 404, "Document was not found");
        if (fd>=0)
                close(fd);
+done:
        if (decoded)
                evhttp_uri_free(decoded);
        if (decoded_path)
                free(decoded_path);
        if (whole_path)
                free(whole_path);
+       if (evb)
+               evbuffer_free(evb);
 }
 
 static void