[cups.development] found a resource leak in file socket.c

Helge Blischke h.blischke at acm.org
Tue Jun 30 12:10:18 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





More information about the cups mailing list