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

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



So, I just had an idea
How would one go about forcefully closing a bufferevent correctly?
I'm currently doing this:
    bool Socket::Close() {
        if (!m_event) {
            sys_err("Tried to close socket while m_event is a nullptr");
            return false;
        }
        evutil_socket_t fd = bufferevent_getfd(m_event);
        if (fd < 0) {
sys_err("Tried to close socket while m_event is not connected (fd < 0)");
            return false;
        }
        if (evutil_closesocket(fd) < 0) {
            int err = evutil_socket_geterror(fd);
sys_err("Closing the socket %d failed. %s errorcode (%d)", fd, evutil_socket_error_to_string(err), err);
            return false;
        }
        // Simulate EOf event so we can handle disconnect properly
        OnEvent(BEV_EVENT_EOF);
        return true;
    }
This might be the reason the stuff is corrupted (dont know why I didnt think of this earlier, sorry!)
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.