BTW, it it a requirement to use malloc, and if so, when would I need to free the memory allocated by it?
Inotify is expecting you to read into a buffer. You could allocate that buffer from the GC with core.memory.malloc() instead.
You want to free the memory once you finish processing the event.