Fix bad memory access during shutdown

Bad idea to use a pointer into a realloced array..
This commit is contained in:
Kim Woelders 2021-05-06 13:39:01 +02:00
parent 8c9d306fc1
commit 50d0dcd467
4 changed files with 20 additions and 21 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2007-2015 Kim Woelders
* Copyright (C) 2007-2021 Kim Woelders
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
@ -50,7 +50,7 @@ typedef struct {
static DbusData dbus_data;
static EventFdDesc *db_efd = NULL;
static int db_efd = 0;
static dbus_bool_t
DbusWatchAdd(DBusWatch * watch, void *data __UNUSED__)

View File

@ -347,7 +347,7 @@ ExtVersion(int ext_ix)
* File descriptor handling
*/
struct _EventFdDesc {
typedef struct {
#if 0 /* Unused */
const char *name;
#endif
@ -355,7 +355,7 @@ struct _EventFdDesc {
int fd;
#endif
void (*handler)(void);
};
} EventFdDesc;
static int nfds = 0;
#if USE_EVHAN_POLL
@ -363,34 +363,34 @@ static struct pollfd *pfdl = NULL;
#endif
static EventFdDesc *pfds = NULL;
EventFdDesc *
int
EventFdRegister(int fd, EventFdHandler * handler)
{
nfds++;
int efd;
efd = nfds++;
pfds = EREALLOC(EventFdDesc, pfds, nfds);
#if USE_EVHAN_POLL
pfdl = EREALLOC(struct pollfd, pfdl, nfds);
pfdl[nfds - 1].fd = fd;
pfdl[efd].fd = fd;
#elif USE_EVHAN_SELECT
pfds[nfds - 1].fd = fd;
pfds[efd].fd = fd;
#endif
pfds[nfds - 1].handler = handler;
pfds[efd].handler = handler;
return pfds + (nfds - 1);
return efd;
}
void
EventFdUnregister(EventFdDesc * efd)
EventFdUnregister(int efd)
{
int ix = efd - pfds;
#if USE_EVHAN_POLL
if (pfdl[ix].fd > 0)
pfdl[ix].fd = -pfdl[ix].fd;
if (pfdl[efd].fd > 0)
pfdl[efd].fd = -pfdl[efd].fd;
#elif USE_EVHAN_SELECT
pfds[ix].fd = -1;
pfds[efd].fd = -1;
#endif
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2006-2013 Kim Woelders
* Copyright (C) 2006-2021 Kim Woelders
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
@ -43,10 +43,9 @@ void EventsMain(void);
void EventShow(const XEvent * ev);
void EventShowError(const XEvent * ev);
typedef struct _EventFdDesc EventFdDesc;
typedef void (EventFdHandler) (void);
EventFdDesc *EventFdRegister(int fd, EventFdHandler * handler);
void EventFdUnregister(EventFdDesc * efd);
int EventFdRegister(int fd, EventFdHandler * handler);
void EventFdUnregister(int efd);
int EventsUpdateXY(int *px, int *py);
void EventsBlock(int mode);

View File

@ -56,7 +56,7 @@ static char restarting = 0;
static char *sm_client_id = NULL;
static SmcConn sm_conn = NULL;
static EventFdDesc *sm_efd = NULL;
static int sm_efd = 0;
static void
set_save_props(SmcConn smc_conn, int master_flag)