From e3a1aae751e2474d95bc199fa2e2d5fc015f3afb Mon Sep 17 00:00:00 2001 From: icy17 <1061499390@qq.com> Date: Wed, 10 Apr 2024 18:44:08 +0800 Subject: [PATCH] Fix potential Null pointer dereference in server.c --- benchmark/throughput/libevent/server.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/benchmark/throughput/libevent/server.c b/benchmark/throughput/libevent/server.c index d4649c3f3..359a09bf2 100644 --- a/benchmark/throughput/libevent/server.c +++ b/benchmark/throughput/libevent/server.c @@ -56,6 +56,11 @@ static void accept_conn_cb(struct evconnlistener *listener, struct event_base *base = evconnlistener_get_base(listener); struct bufferevent *bev = bufferevent_socket_new( base, fd, BEV_OPT_CLOSE_ON_FREE); + + if (bev == NULL) { + perror("Couldn't create bufferevent"); + return; + } set_tcp_no_delay(fd); bufferevent_setcb(bev, echo_read_cb, NULL, echo_event_cb, NULL); @@ -89,6 +94,10 @@ int main(int argc, char **argv) } evstop = evsignal_new(base, SIGHUP, signal_cb, base); + if (!evstop) { + puts("Couldn't create event"); + return 1; + } evsignal_add(evstop, NULL); /* Clear the sockaddr before using it, in case there are extra