found a resource leak in file socket.c

Ettl Martin ettl.martin at gmx.de
Tue Jun 30 13:04:37 PDT 2009


> Martin Ettl wrote:
>
> > Hi all,
> >
> > i have checked the sources of cups with the static code analysis tool
> > cppcheck. It found a resource leak in file socket.c at line 259. The tool
> > prints the following output:
> >
> >  [cups-1.3.10/backend/socket.c:259]: (error) Resource leak: print_fd
> >
> > Take a look at the sourcecode to line 259:
> >
> > ....
> >  if ((addrlist = httpAddrGetList(hostname, AF_UNSPEC, portname)) == NULL)
> >   {
> >     _cupsLangPrintf(stderr, _("ERROR: Unable to locate printer
> >     \'%s\'!\n"),
> >                     hostname);
> > 259    return (CUPS_BACKEND_STOP);
> >   }
> > ....
> >
> > Indeed, the file is never closed. A possible fix could be:
> >
> > ....
> >  if ((addrlist = httpAddrGetList(hostname, AF_UNSPEC, portname)) ==NULL)
> >   {
> >     _cupsLangPrintf(stderr, _("ERROR: Unable to locate printer\'%s '!\n"),
> >                     hostname);
> >     close(print_fd);
> >     return (CUPS_BACKEND_STOP);
> >   }
> > .....
> >
> >
> > Best regards
> >
> > Ettl Martin
>
> I think that isn't really a resource leak, as any open file descriptors are
> cclosed on exit by default.
>
> Helge
>
I agree with you that they are closed when the programm terminates. But (no offense) it is a bad programming style, but this is only my opinion.

Best regards

Martin




More information about the cups-devel mailing list