kwo pushed a commit to branch master.

http://git.enlightenment.org/e16/e16.git/commit/?id=50d0dcd467808438aaf56ba335be3f4834466506

commit 50d0dcd467808438aaf56ba335be3f4834466506
Author: Kim Woelders <k...@woelders.dk>
Date:   Thu May 6 13:39:01 2021 +0200

    Fix bad memory access during shutdown
    
    Bad idea to use a pointer into a realloced array..
---
 src/edbus.c   |  4 ++--
 src/events.c  | 28 ++++++++++++++--------------
 src/events.h  |  7 +++----
 src/session.c |  2 +-
 4 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/src/edbus.c b/src/edbus.c
index 266e56d0..85f1e743 100644
--- a/src/edbus.c
+++ b/src/edbus.c
@@ -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__)
diff --git a/src/events.c b/src/events.c
index 16b49b94..2e8010d6 100644
--- a/src/events.c
+++ b/src/events.c
@@ -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
 }
 
diff --git a/src/events.h b/src/events.h
index f484db2a..f52aa052 100644
--- a/src/events.h
+++ b/src/events.h
@@ -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);
diff --git a/src/session.c b/src/session.c
index 2b2881f4..3e911433 100644
--- a/src/session.c
+++ b/src/session.c
@@ -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)

-- 


Reply via email to