From ffbdd1aa20c8a20a8e9dcd3cec644b6dfa3c6acb Mon Sep 17 00:00:00 2001 From: Tom Schwindl Date: Sat, 10 Sep 2022 15:18:31 +0200 Subject: [PATCH] rio: check the return value of malloc(3) --- src/cmd/rio/client.c | 5 +++++ src/cmd/rio/main.c | 4 ++++ src/cmd/rio/manage.c | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/src/cmd/rio/client.c b/src/cmd/rio/client.c index 256261ca..d78be626 100644 --- a/src/cmd/rio/client.c +++ b/src/cmd/rio/client.c @@ -151,6 +151,11 @@ getclient(Window w, int create) return 0; c = (Client *)malloc(sizeof(Client)); + if (!c){ + fprintf(stderr, "rio: Failed to allocate memory\n"); + exit(1); + } + memset(c, 0, sizeof(Client)); c->window = w; /* c->parent will be set by the caller */ diff --git a/src/cmd/rio/main.c b/src/cmd/rio/main.c index 1e0b3797..09c1316e 100644 --- a/src/cmd/rio/main.c +++ b/src/cmd/rio/main.c @@ -213,6 +213,10 @@ main(int argc, char *argv[]) num_screens = ScreenCount(dpy); screens = (ScreenInfo *)malloc(sizeof(ScreenInfo) * num_screens); + if (!screens){ + fprintf(stderr, "rio: Failed to allocate memory\n"); + return 1; + } for(i = 0; i < num_screens; i++) initscreen(&screens[i], i, background); diff --git a/src/cmd/rio/manage.c b/src/cmd/rio/manage.c index b068a101..07c9d479 100644 --- a/src/cmd/rio/manage.c +++ b/src/cmd/rio/manage.c @@ -320,6 +320,11 @@ getcmaps(Client *c) c->cmapwins = cw; c->wmcmaps = (Colormap*)malloc(n*sizeof(Colormap)); + if (!c->wmcmaps){ + fprintf(stderr, "rio: Failed to allocate memory\n"); + exit(1); + } + for(i = 0; i < n; i++){ if(cw[i] == c->window) c->wmcmaps[i] = c->cmap;