[Mauiusers] Patch to fix a possible double free

Garrick Staples garrick at usc.edu
Mon Aug 13 15:03:04 MDT 2007


> > I have a (possibly naive) snippet of code from another type of
> > daemon process where the files are properly closed:
> > 
> >         /* Become a daemon */
> >         pid = fork();
> >         if (pid > 0) {          /* Parent */
> >                 /* Close parent's streams */
> >                fclose (stdin);
> >                fclose (stdout);
> >                fclose (stderr);
> >                 return(0);
> >         } else if (pid < 0) {   /* Error */
> >                 printf("%s: Could not fork child process\n", argv[0]);
> >                 return(-1);
> >         }
> > 
> > The Maui code in src/server/OServer.c doesn't close file descriptors,
> > which IMHO it ought to do.  Ronny has even more detailed suggestions
> > above which I don't claim to understand fully.

*closing* is a bad idea because you don't want those descriptors to be reused by future function calls.  Imagine some random debug printf() going to some all-important network socket that happened to get fd 2.

You really want them to be associated with /dev/null.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.supercluster.org/pipermail/mauiusers/attachments/20070813/d00ade6d/attachment.bin


More information about the mauiusers mailing list