ceph/ceph — pull request #3255 by tchaikov (2014-12-25 15:19:54+00:00)
Title: AsyncMessenger: fix the leak of file_events

happy new year @yuyuyu101. not sure if you have fixed this in some floating PR. i checked #3211 and #3219, neither of them addresses this.

i am wondering why you used a raw array instead of the `std::vector` to manage the `file_events`?

and i am afraid that the `EventCenter::create_file_event()` can break in some cases:

1. the new `FileEvent` elements are allocated, but their values are not initialized,
2. `_get_file_event()` tries to tell if a newly allocated element is already initialized or not by looking at its mask, and returns it to the caller ... but, wait! the `mask` could be some random bits on the heap, and so are other member variables of `FileEvent`.

also in `EventCenter::create_file_event()`, i see you are managing the memory using a strategy resembling the one used by `std::vector`.
maybe we'd better use `std::vector()` directly?

another concern is that, there is good chance that the process is holding some other file descriptors not watched by the `EventCenter` instance? so there could be "holes" in the `file_events` array? this array serves well as an unordered map from fd to `FileEvent` regarding to the time performance, but how about the space performance? maybe we can put the fd *into* the `FileEvent`? and walk through the array when looking for an element?