The Daemon Pattern

This is a common pattern seen in daemons (in C like languages).

int some_func()
     struct foo_s *foo = (struct foo_s *) malloc(sizeof(struct foo_s));
     while (1) {

     return r;

The unreachable free() makes no sense. A missing free(), though unreachable, annoys a purist. Considering the scope and visibility of foo(), putting it on the heap is not the best approach. The scope is within some_func(), and the visibility is until the process exits (killed).

Continue reading “The Daemon Pattern”