Hi,

I'm not a good expert of C, but trying to build a simple example using
libevent.

I've succesfully build a very simple http server with the stupid "Hello
World" message.

Now I'm trying to capture a SIGINT as shown in "sample/signal-test.c"
 present in the libevent tar file.

Unfortunately, I receive a segmentation fault
"
*** glibc detected *** ./test: double free or corruption (!prev):
0x0804f1e0 ***
======= Backtrace: =========
/lib/libc.so.6[0xb7e54c06]
/lib/libc.so.6(cfree+0x89)[0xb7e568c9]
/usr/lib/libevent-1.3d.so.1(evhttp_free+0x4f)[0xb7f5933f]
./test(signal_cb+0x55)[0x8048995]
/usr/lib/libevent-1.3d.so.1(event_base_loop+0x242)[0xb7f56832]
/usr/lib/libevent-1.3d.so.1(event_loop+0x29)[0xb7f56ac9]
/usr/lib/libevent-1.3d.so.1(event_dispatch+0x1e)[0xb7f56aee]
./test[0x804891a]
/lib/libc.so.6(__libc_start_main+0xe0)[0xb7e04f90]
"


Does some can exaplain it ?
If I remove the http_free(http_server) command, the process never stop any
more ;-(.
I need to use a "kill -9" to stop it.
Why this is so ? is there some event not yet complete ?


Thanks.





ANNEXE:
--------

test.c:
-------


1: #include <Python.h>
2: #ifdef WIN32
3: #include <winsock2.h>
4: #include <windows.h>
5: #endif
6:
7: #ifdef HAVE_CONFIG_H
8: #include "config.h"
9: #endif
10:
11: #include <sys/types.h>
12: #include <sys/stat.h>
13: #ifdef HAVE_SYS_TIME_H
14: #include <sys/time.h>
15: #endif
16: #include <sys/queue.h>
17: #ifndef WIN32
18: #include <sys/socket.h>
19: #include <sys/signal.h>
20: #include <unistd.h>
21: #endif
22: #include <netdb.h>
23: #include <fcntl.h>
24: #include <stdlib.h>
25: #include <stdio.h>
26: #include <string.h>
27: #include <errno.h>
28:
29: #include "event.h"
30: #include "evhttp.h"
31: #include "log.h"
32: #include "http-internal.h"
33:
34: struct evhttp* httpd;
35:
36: void root_handler( struct evhttp_request *req, void *arg)
37: {
38: struct evbuffer *evb=evbuffer_new();
39: evbuffer_add_printf(evb, "Hello World!");
40: printf("Request from %s:", req->remote_host);
41: printf("%i\n", req->remote_port);
42: evhttp_send_reply(req, HTTP_OK, "OK", evb);
43: evbuffer_free(evb);
44: }
45:
46:
47: int called = 0;
48:
49: void
50: signal_cb(int fd, short event, void *arg)
51: {
52: struct event *signal = arg;
53:
54: printf("got signal %d\n", EVENT_SIGNAL(signal));
55: if (called >= 2)
56: event_del(signal);
57: evhttp_free(httpd);
58: called++;
59: }
60:
61:
62:
63: int main(int argc, char **argv)
64: {
65: struct event signal_int;
66: event_init();
67: event_set(&signal_int, SIGINT, EV_SIGNAL|EV_PERSIST, signal_cb,
&signal_int);
68: event_add(&signal_int, NULL);
69: httpd=evhttp_start("0.0.0.0", 8080);
70: evhttp_set_cb(httpd, "/", root_handler, NULL);
71: printf("start dispatch\n");
72: event_dispatch();
73: printf("stop dispatch\n");
74: return 0;
75: }
76:


compilation commands:
---------------------
gcc -g  -O3 -Wall -Wstrict-prototypes -fPIC
-I/var/abs/local/libevent/src/libevent-1.3b -I/usr/include/python2.5 -c
test.c -o test.o
gcc  -g -O2 -Wall -o test test.o -levent -lnsl -lrt -lresolv


_______________________________________________
Libevent-users mailing list
Libevent-users@monkey.org
http://monkey.org/mailman/listinfo/libevent-users

Reply via email to