Question

I am working on a project to implement an IRC daemon in C. This is still in a very early development stage, and all it does for now is to accept new connections on the main process, and for each new connection, it creates a thread. Every message from any client is broadcasted to all other connected clients.

I am using libev's callback mechanism so that threads do not block on a socket read. Each thread uses its own separate event loop. Here's a piece of my main() function:

int main(int argc, char *argv[]) {

    int portno = 6667;

    /* Libev stuff */
    struct ev_loop *loop = EV_DEFAULT;
    struct ev_io socket_watcher;

    /* Here, I create a socket called mainsock_fd, and then call bind() and listen() 
        ...
    */

    /* At this point, we're ready to accept new clients. Set the callback function for new connections */
    ev_io_init(&socket_watcher, connection_cb, mainsock_fd, EV_READ);
    ev_io_start(loop, &socket_watcher);

    /* This is where the problem lies */
    ev_loop(loop, 0);

    /* ... */

    return 0;
}

I am no libev expert. I have been reading libev's documentation and example programs. This code works exactly as expected, but when I run it through valgrind, I get this error:

==20984== Command: ./yaircd
==20984== 
==20984== Invalid read of size 1
==20984==    at 0x40638D1: ev_run (in /usr/lib/libev.so.4.0.0)
==20984==    by 0x804923F: ev_loop (ev.h:820)
==20984==    by 0x8049410: main (yaircd.c:71)
==20984==  Address 0xbedf52df is just below the stack ptr.  To suppress, use: --workaround-gcc296-bugs=yes

Line 71 is this instruction:

ev_loop(loop, 0);

The error appears immediately after I start the program, with no clients connected. Just the fact that I call ev_loop causes this error.

I don't know how to fix it. What I have coded so far is going to be the core of the IRC server, and I want to be absolutely sure no bugs exist. I'd like to have a clean valgrind output.

Any suggestions?

UPDATE: I compiled and executed their example program (http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#EXAMPLE_PROGRAM), and valgrind reports the same error on it. I'm guessing this is some bug in libev, or the example is not properly coded. I also read their section about valgrind - http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#VALGRIND - but found nothing special about it. I guess I'll try their mailing list.

Was it helpful?

Solution

A similar problem has been submitted in libev's mailing list before (see http://lists.schmorp.de/pipermail/libev/2013q2/002172.html).

According to the development crew, this is a harmless bug in valgrind, as pointed out in this reply: http://lists.schmorp.de/pipermail/libev/2013q2/002173.html

No, this is just a (harmless) bug in valgrind, which apparently doesn't recognise the lock prefix correctly, or somesuch.

It doesn't affect correctness inside and outside of valgrind.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top