summaryrefslogtreecommitdiff
path: root/sample
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2011-04-14 14:15:13 -0400
committerNick Mathewson <nickm@torproject.org>2011-04-14 14:17:58 -0400
commit2e9f66554897279f9aae2ce5a3933b99b6e08e38 (patch)
tree50953d426bdc31d1c7d85c0d09267c2a126049b5 /sample
parent3417f6808d4c86b02148cde4f7a32b18d8d260b4 (diff)
downloadlibevent-2e9f66554897279f9aae2ce5a3933b99b6e08e38.tar.gz
Fix a couple of memory leaks in samples/http-server.c. Found by Dave Hart.
Diffstat (limited to 'sample')
-rw-r--r--sample/http-server.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/sample/http-server.c b/sample/http-server.c
index d5212c51..05dc165e 100644
--- a/sample/http-server.c
+++ b/sample/http-server.c
@@ -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