1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-20 21:08:08 +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:
Carlos R. Mafra
2009-08-18 00:30:17 +02:00
parent be0d694dc2
commit f18567db9a

View File

@@ -315,28 +315,29 @@ DispatchEvent(XEvent *event)
*----------------------------------------------------------------------
*/
/* Allow for 1024 simultanious events */
#define BUFF_SIZE ((sizeof(struct inotify_event)+FILENAME_MAX)*1024)
#define BUFF_SIZE ((sizeof(struct inotify_event) + 16)*512)
void inotifyHandleEvents (int fd, int wd)
{
extern void wDefaultsCheckDomains();
ssize_t eventQLength, i = 0;
char buff[BUFF_SIZE] = {0};
extern void wDefaultsCheckDomains();
int oneShotFlag=0; /* Only check config once per read of the event queue */
/* Check config only 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
* 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
* a few entries before a read().
*/
eventQLength = read (fd, buff, BUFF_SIZE);
eventQLength = read(fd, buff, BUFF_SIZE);
/* check what events occured */
/* Should really check wd here too, but for now we only have one watch! */
while (i < eventQLength) {
struct inotify_event *pevent = (struct inotify_event *)&buff[i];
/*
* see inotify.h for event types.
*/
@@ -357,13 +358,11 @@ void inotifyHandleEvents (int fd, int wd)
fprintf(stdout,"wmaker: reading config files in defaults database.\n");
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 */
}
} /* inotifyHandleEvents */
/* move to next event in the buffer */
i += sizeof(struct inotify_event) + pevent->len;
}
}
/*
*----------------------------------------------------------------------