Hi
I've checked out lastest svn (rev 1123), and built a small test
program which basically makes a GET and takes ownership of response in
callback (to be freed later)
If targeted HTTP server is down, the program segfaults because HTTP
request is freed twice, even if evhttp_request_own has been used to
explicitly tell libevent not to free it.
Digging it a bit, I found out that evhttp_connection_cb_cleanup frees
request despite own flag has been set.
I've patched it, but if I may be wrong and there may be another mean
to know that request has failed (transport speaking).
Best regards
Guillaume
$ cat > test.c << EOF
#include <event.h>
#include <assert.h>
#include <event2/http.h>
static struct evhttp_request *resp = NULL;
static struct event_base *base;
static void request_done(struct evhttp_request *req, void *arg) {
evhttp_request_own(req);
resp = req;
}
void rest_process(
enum evhttp_cmd_type method, const char *host, int port, const char *uri,
struct evbuffer *body) {
struct evhttp_connection *conn;
struct evhttp_request *req;
int ret;
conn = evhttp_connection_base_new(base, host, port);
assert(conn != NULL);
req = evhttp_request_new(request_done, NULL);
assert(req != NULL);
ret = evhttp_make_request(conn, req, method, uri);
assert(ret == 0);
}
int main(int argc, char **argv) {
base = event_init();
rest_process(EVHTTP_REQ_GET, "127.0.0.1", 8080, "/path", NULL);
event_base_loop(base,0);
assert(resp != NULL);
evhttp_request_free(resp);
return 0;
}
EOF
Index: http.c
===================================================================
--- http.c (revision 1123)
+++ http.c (working copy)
@@ -1081,6 +1081,10 @@
/* we might want to set an error here */
request->cb(request, request->cb_arg);
+
+ if (evhttp_request_is_owned(request))
+ continue;
+
evhttp_request_free(request);
}
}
_______________________________________________
Libevent-users mailing list
[email protected]
http://monkeymail.org/mailman/listinfo/libevent-users