libwebsite icon indicating copy to clipboard operation
libwebsite copied to clipboard

Leak of repy_body

Open jasongilanfarr opened this issue 13 years ago • 2 comments

req->reply_body is not freed for regular http request/responses. Since the consumer of the API doesn't know when the reply completes, this must be handled by libwebsite.

diff --git a/src/core.c b/src/core.c
index a500225..c34723f 100644
--- a/src/core.c
+++ b/src/core.c
@@ -114,6 +114,7 @@ static ws_request_t *ws_request_new(ws_connection_t *conn) {
 
 int ws_request_free(ws_request_t *req) {
     obstack_free(&req->pieces, NULL);
+    free(req->reply_body);
     free(req);
 }

jasongilanfarr avatar Jul 21 '13 18:07 jasongilanfarr

@americandream, in the zerogw which is primary project using libwebsite, reply body is either allocated in obstack or uses a static string or uses zeromq message. First two doesn't need separate "free" call and the latter needs a custom routine for that. You can free the body in callback set by ws_FINISH_CB macro.

tailhook avatar Jul 21 '13 19:07 tailhook

I realized that and ended up using ws_FINISH_CB.

jasongilanfarr avatar Jul 21 '13 19:07 jasongilanfarr