Changeset: c0a20cf4e141 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c0a20cf4e141
Modified Files:
        monetdb5/modules/mal/mal_mapi.c
Branch: Jul2012
Log Message:

Fix resource leakage in case of error.
Found by coverity.


diffs (47 lines):

diff --git a/monetdb5/modules/mal/mal_mapi.c b/monetdb5/modules/mal/mal_mapi.c
--- a/monetdb5/modules/mal/mal_mapi.c
+++ b/monetdb5/modules/mal/mal_mapi.c
@@ -453,6 +453,7 @@ SERVERlisten(int *Port, str *Usockfile, 
                                        port++;
                                        continue;
                                }
+                               closesocket(sock);
                                throw(IO, "mal_mapi.listen",
                                                OPERATION_FAILED ": bind to 
stream socket port %d "
                                                "failed: %s", port, 
strerror(errno));
@@ -461,10 +462,12 @@ SERVERlisten(int *Port, str *Usockfile, 
                        }
                } while (1);
 
-               if (getsockname(sock, (SOCKPTR) &server, &length) < 0)
+               if (getsockname(sock, (SOCKPTR) &server, &length) < 0) {
+                       closesocket(sock);
                        throw(IO, "mal_mapi.listen",
                                        OPERATION_FAILED ": failed getting 
socket name: %s",
                                        strerror(errno));
+               }
                listen(sock, maxusers);
        }
 #ifdef HAVE_SYS_UN_H
@@ -478,10 +481,12 @@ SERVERlisten(int *Port, str *Usockfile, 
 
                /* prevent silent truncation, sun_path is typically around 108
                 * chars long :/ */
-               if (strlen(usockfile) >= sizeof(userver.sun_path))
+               if (strlen(usockfile) >= sizeof(userver.sun_path)) {
+                       closesocket(usock);
                        throw(MAL, "mal_mapi.listen",
                                        OPERATION_FAILED ": UNIX socket path 
too long: %s",
                                        usockfile);
+               }
 
                userver.sun_family = AF_UNIX;
                strncpy(userver.sun_path, usockfile, sizeof(userver.sun_path));
@@ -489,6 +494,7 @@ SERVERlisten(int *Port, str *Usockfile, 
                length = (SOCKLEN) sizeof(userver);
                unlink(usockfile);
                if (bind(usock, (SOCKPTR) &userver, length) < 0) {
+                       closesocket(usock);
                        unlink(usockfile);
                        throw(IO, "mal_mapi.listen",
                                        OPERATION_FAILED ": binding to UNIX 
socket file %s failed: %s",
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to