]> arthur.barton.de Git - netatalk.git/blobdiff - etc/papd/main.c
fix a leak socket on error in papd
[netatalk.git] / etc / papd / main.c
index 48723df01f031f16c812f6d616cfa2087394c028..724815c395da7cbe55e2e8eb1fbadb0c1e735cf3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: main.c,v 1.19 2005-04-28 20:49:49 bfernhomberg Exp $
+ * $Id: main.c,v 1.21 2007-05-14 18:38:52 didg Exp $
  *
  * Copyright (c) 1990,1995 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -426,7 +426,6 @@ int main( ac, av )
                     }
 #endif /* HAVE_CUPS */
 
-
                    /*
                     * If this fails, we've run out of sockets. Rather than
                     * just die(), let's try to continue. Maybe some sockets
@@ -435,10 +434,13 @@ int main( ac, av )
                    if (( atp = atp_open( ATADDR_ANYPORT, 
                                          &pr->p_addr)) == NULL ) {
                        LOG(log_error, logtype_papd, "atp_open: %m" );
-                       rbuf[ 2 ] = rbuf[ 3 ] = 0xff;
+                       rbuf[ 2 ] = rbuf[ 3 ] = 0xff;  /* printer busy */
+                       rbuf[ 4 ] = 0; /* FIXME is it right? */
                        err = 1;
                    }
-                   rbuf[ 4 ] = atp_sockaddr( atp )->sat_port;
+                   else {
+                      rbuf[ 4 ] = atp_sockaddr( atp )->sat_port;
+                    }
                    rbuf[ 5 ] = oquantum;
                    rbuf[ 6 ] = rbuf[ 7 ] = 0;
 
@@ -451,16 +453,20 @@ int main( ac, av )
                     */
                    if ( atp_sresp( pr->p_atp, &atpb ) < 0 ) {
                        LOG(log_error, logtype_papd, "atp_sresp: %m" );
-                       continue;
+                       err = 1;
                    }
 
                    if ( err ) {
+                       if (atp) {
+                          atp_close(atp);
+                        }
                        continue;
                    }
 
                    switch ( c = fork()) {
                    case -1 :
                        LOG(log_error, logtype_papd, "fork: %m" );
+                        atp_close(atp);
                        continue;
 
                    case 0 : /* child */