[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[Libevent-users] Valgrind, evmap_io_add Invalid write of size 4



Hey,

I was just debugging some crashes and memory leaks with valgrind and this came up: [warn] Epoll MOD(4) on fd 61 failed. Old events were 6; read change was 2 (del); write change was 0 (none): Bad file descriptor
==10706== Invalid write of size 4
==10706== at 0x5348FE6: evmap_io_add (in /usr/lib/i386-linux-gnu/libevent-2.0.so.5.1.7) ==10706== by 0x5337BAA: event_add (in /usr/lib/i386-linux-gnu/libevent-2.0.so.5.1.7) ==10706== by 0x5343A57: _bufferevent_add_event (in /usr/lib/i386-linux-gnu/libevent-2.0.so.5.1.7) ==10706== by 0x53441DC: be_socket_enable (in /usr/lib/i386-linux-gnu/libevent-2.0.so.5.1.7) ==10706== by 0x5343475: bufferevent_enable (in /usr/lib/i386-linux-gnu/libevent-2.0.so.5.1.7) ==10706== by 0x806974F: net::Socket::Setup(int, sockaddr_in) (Socket.cpp:77) ==10706== by 0x8068A96: net::Listener<net::socket::Client>::Accept(int, sockaddr_in*) (Listener.hpp:85) ==10706== by 0x806885A: net::Listener<net::socket::Client>::SOnAccept(evconnlistener*, int, sockaddr*, int, void*) (Listener.hpp:112) ==10706== by 0x53462E1: listener_read_cb (in /usr/lib/i386-linux-gnu/libevent-2.0.so.5.1.7)
==10706==    by 0x78BBD23D: ???
==10706== Address 0x61d44e80 is 176 bytes inside a block of size 4,056 free'd [...] Non libevent related stuff, some free'd memory which has nothing to do with libevent

net::Listener:
        void Accept(evutil_socket_t fd, sockaddr_in * addr) {
sys_log(0, "New connection on %s:%d from %s", m_bind_ip.c_str(), m_bind_port, inet_ntoa(addr->sin_addr));
            SocketType* s = new SocketType();
            s->SetID(m_socket_id++);
            if (!s->Setup(fd, *addr)) {
                sys_err("Failed to set up socket %d", m_socket_id);
                delete s;
                return;
            }
            if (!OnAccept(s)) {
                delete s;
                return;
            }
m_sockets.insert(std::pair<unsigned int, SocketType*>(s->GetID(), s));
        }
static void SOnAccept(evconnlistener *, evutil_socket_t fd, struct sockaddr * addr, int socklen, void * arg) {
            if (!arg) {
                sys_err("Recieved nullpointer as arg");
                return;
            }
            Listener<SocketType>* l = (Listener<SocketType>*) arg;
            l->Accept(fd, (sockaddr_in*) addr);
        }
The callback is registered like this:
m_listener = evconnlistener_new_bind(NetworkManager::instance().GetEventBase(), Listener::SOnAccept, this, LEV_OPT_REUSEABLE | LEV_OPT_CLOSE_ON_FREE, 1024, (sockaddr*) & sa, sizeof (sa));

 Socket::Setup:
    bool Socket::Setup(evutil_socket_t fd, sockaddr_in addr) {
        if (m_event) {
            sys_err("Socket already set up");
            return false;
        }
        m_addr = addr;
m_event = bufferevent_socket_new(NetworkManager::instance().GetEventBase(), fd, _SOCKET_DEFAULT_FLAGS); bufferevent_setcb(m_event, Socket::SOnRead, Socket::SOnWrite, Socket::SOnEvent, this);
        bufferevent_enable(m_event, EV_READ | EV_WRITE);
        OnConnect();
        return true;
    }
Is this just a false positive or am I doing something wrong?
This doesn't happen every time there's a new connection, in fact, it only seems to happen once

I am running on Debian Wheezy & libevent 2.0.19

I am also getting a bunch of these type errors:
[warn] Epoll MOD(4) on fd 68 failed. Old events were 6; read change was 2 (del); write change was 0 (none): Bad file descriptor

Usually after it hit a breakpoint or it couldn't keep up (running this in a single thread+valgrind, stuff gets sloow) Am I right to assume I can just ignore it as it only seems to happen when running valgrind?


- imer
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.