mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-21 05:18:06 +01:00
inotifyHandleEvents: Reduce buffer size to avoid huge memory consumption
inotifyHandleEvents() was allocating a buffer of size (sizeof(struct inotify_event) + FILENAME_MAX)*1024 where FILENAME_MAX is #defined to be 4096 in stdio_lim.h, therefore it was more than 4 MB! Reduce it by using 16 instead of FILENAME_MAX and 512 instead of 1024. Now valgrind does not complain about things like Invalid write of size 8 at 0x42002F: inotifyHandleEvents (event.c:323) by 0x7FF00020F: ??? Address 0x7febfc148 is on thread 1's stack I also made some small coding style changes.
This commit is contained in:
21
src/event.c
21
src/event.c
@@ -315,22 +315,23 @@ DispatchEvent(XEvent *event)
|
|||||||
*----------------------------------------------------------------------
|
*----------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Allow for 1024 simultanious events */
|
#define BUFF_SIZE ((sizeof(struct inotify_event) + 16)*512)
|
||||||
#define BUFF_SIZE ((sizeof(struct inotify_event)+FILENAME_MAX)*1024)
|
|
||||||
void inotifyHandleEvents (int fd, int wd)
|
void inotifyHandleEvents (int fd, int wd)
|
||||||
{
|
{
|
||||||
|
extern void wDefaultsCheckDomains();
|
||||||
ssize_t eventQLength, i = 0;
|
ssize_t eventQLength, i = 0;
|
||||||
char buff[BUFF_SIZE] = {0};
|
char buff[BUFF_SIZE] = {0};
|
||||||
extern void wDefaultsCheckDomains();
|
/* Check config only once per read of the event queue */
|
||||||
int oneShotFlag=0; /* Only check config once per read of the event queue */
|
int oneShotFlag = 0;
|
||||||
|
|
||||||
/* Read off the queued events
|
/*
|
||||||
|
* Read off the queued events
|
||||||
* queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
|
* queue overflow is not checked (IN_Q_OVERFLOW). In practise this should
|
||||||
* not occur; the block is on Xevents, but a config file change will normally
|
* not occur; the block is on Xevents, but a config file change will normally
|
||||||
* occur as a result of an Xevent - so the event queue should never have more than
|
* occur as a result of an Xevent - so the event queue should never have more than
|
||||||
* a few entries before a read().
|
* a few entries before a read().
|
||||||
*/
|
*/
|
||||||
eventQLength = read (fd, buff, BUFF_SIZE);
|
eventQLength = read(fd, buff, BUFF_SIZE);
|
||||||
|
|
||||||
/* check what events occured */
|
/* check what events occured */
|
||||||
/* Should really check wd here too, but for now we only have one watch! */
|
/* Should really check wd here too, but for now we only have one watch! */
|
||||||
@@ -357,13 +358,11 @@ void inotifyHandleEvents (int fd, int wd)
|
|||||||
fprintf(stdout,"wmaker: reading config files in defaults database.\n");
|
fprintf(stdout,"wmaker: reading config files in defaults database.\n");
|
||||||
wDefaultsCheckDomains(NULL);
|
wDefaultsCheckDomains(NULL);
|
||||||
}
|
}
|
||||||
/* Check for filename (length of name (len) > 0) */
|
|
||||||
/* if (pevent->len) printf ("name=%s\n", pevent->name); */
|
|
||||||
|
|
||||||
i += sizeof(struct inotify_event) + pevent->len; /* move to next event in the buffer */
|
/* move to next event in the buffer */
|
||||||
|
i += sizeof(struct inotify_event) + pevent->len;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} /* inotifyHandleEvents */
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*----------------------------------------------------------------------
|
*----------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user