Skip to content

Instantly share code, notes, and snippets.

@postwait
Created April 6, 2012 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save postwait/2322935 to your computer and use it in GitHub Desktop.
Save postwait/2322935 to your computer and use it in GitHub Desktop.
diff --git a/src/noit_rest.c b/src/noit_rest.c
index b3aa3e6..07c5120 100644
--- a/src/noit_rest.c
+++ b/src/noit_rest.c
@@ -290,10 +290,18 @@ noit_rest_request_dispatcher(noit_http_session_ctx *ctx) {
rest_request_handler handler = restc->fastpath;
if(!handler) handler = noit_http_get_handler(restc);
if(handler) {
+ void *old_closure = restc, *new_closure;
noit_http_response *res = noit_http_session_response(ctx);
int rv;
rv = handler(restc, restc->nparams, restc->params);
- if(noit_http_response_closed(res)) noit_http_rest_clean_request(restc);
+ /* If the request is closed, we need to cleanup. However
+ * if the dispatch closure has changed, the callee has done
+ * something (presumably freeing the restc in the process)
+ * and it would be unsafe for us to free it as well.
+ */
+ new_closure = noit_http_session_dispatcher_closure(ctx);
+ if(old_closure == new_closure &&
+ noit_http_response_closed(res)) noit_http_rest_clean_request(restc);
return rv;
}
noit_http_response_status_set(ctx, 404, "NOT FOUND");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment