List:Commits« Previous MessageNext Message »
From:msvensson Date:February 7 2008 10:39am
Subject:bk commit into 6.0 tree (msvensson:1.2530) BUG#34298
View as plain text  
Below is the list of changes that have just been committed into a local
6.0 repository of msvensson.  When msvensson does a push these changes
will be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2008-02-07 10:39:45+01:00, msvensson@stripped +1 -0
  Bug#34298 Client programs generate assertion faults on Windows

  sql-common/client.c@stripped, 2008-02-07 10:39:44+01:00, msvensson@stripped +33 -28
    - Move the "my_socket sock" variable into local scope of the two
    places that creates a socket
    - Use 'closesocket' when closing a socket to be portable
    - Remove 'close' of socket after call to vio_delete skince the socket
    will be closed by vio in that case.
    - Cleanup style of the afftected area

diff -Nrup a/sql-common/client.c b/sql-common/client.c
--- a/sql-common/client.c	2008-01-29 08:50:56 +01:00
+++ b/sql-common/client.c	2008-02-07 10:39:44 +01:00
@@ -1793,7 +1793,6 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
 {
   char		buff[NAME_LEN+USERNAME_LENGTH+100];
   char		*end,*host_info;
-  my_socket	sock;
   ulong		pkt_length;
   NET		*net= &mysql->net;
 #ifdef MYSQL_SERVER
@@ -1885,7 +1884,6 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
     else
     {
       mysql->options.protocol=MYSQL_PROTOCOL_MEMORY;
-      sock=0;
       unix_socket = 0;
       host=mysql->options.shared_memory_base_name;
       my_snprintf(host_info=buff, sizeof(buff)-1,
@@ -1900,12 +1898,8 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
       (unix_socket || mysql_unix_port) &&
       (!host || !strcmp(host,LOCAL_HOST)))
   {
-    host=LOCAL_HOST;
-    if (!unix_socket)
-      unix_socket=mysql_unix_port;
-    host_info=(char*) ER(CR_LOCALHOST_CONNECTION);
-    DBUG_PRINT("info",("Using UNIX sock '%s'",unix_socket));
-    if ((sock = socket(AF_UNIX,SOCK_STREAM,0)) == SOCKET_ERROR)
+    my_socket sock= socket(AF_UNIX, SOCK_STREAM, 0);
+    if (sock == SOCKET_ERROR)
     {
       set_mysql_extended_error(mysql, CR_SOCKET_CREATE_ERROR,
                                unknown_sqlstate,
@@ -1913,12 +1907,28 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
                                socket_errno);
       goto error;
     }
+
     net->vio= vio_new(sock, VIO_TYPE_SOCKET,
                       VIO_LOCALHOST | VIO_BUFFERED_READ);
-    bzero((char*) &UNIXaddr,sizeof(UNIXaddr));
-    UNIXaddr.sun_family = AF_UNIX;
+    if (!net->vio)
+    {
+      DBUG_PRINT("error",("Unknow protocol %d ", mysql->options.protocol));
+      set_mysql_error(mysql, CR_CONN_UNKNOW_PROTOCOL, unknown_sqlstate);
+      closesocket(sock);
+      goto error;
+    }
+
+    host= LOCAL_HOST;
+    if (!unix_socket)
+      unix_socket= mysql_unix_port;
+    host_info= (char*) ER(CR_LOCALHOST_CONNECTION);
+    DBUG_PRINT("info", ("Using UNIX sock '%s'", unix_socket));
+
+    bzero((char*) &UNIXaddr, sizeof(UNIXaddr));
+    UNIXaddr.sun_family= AF_UNIX;
     strmake(UNIXaddr.sun_path, unix_socket, sizeof(UNIXaddr.sun_path)-1);
-    if (my_connect(sock,(struct sockaddr *) &UNIXaddr, sizeof(UNIXaddr),
+
+    if (my_connect(sock, (struct sockaddr *) &UNIXaddr, sizeof(UNIXaddr),
 		   mysql->options.connect_timeout))
     {
       DBUG_PRINT("error",("Got error %d on connect to local server",
@@ -1927,6 +1937,8 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
                                unknown_sqlstate,
                                ER(CR_CONNECTION_ERROR),
                                unix_socket, socket_errno);
+      vio_delete(net->vio);
+      net->vio= 0;
       goto error;
     }
     mysql->options.protocol=MYSQL_PROTOCOL_SOCKET;
@@ -1937,7 +1949,6 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
        (host && !strcmp(host,LOCAL_HOST_NAMEDPIPE)) ||
        (! have_tcpip && (unix_socket || !host && is_NT()))))
   {
-    sock=0;
     if ((hPipe= create_named_pipe(mysql, mysql->options.connect_timeout,
                                   (char**) &host, (char**) &unix_socket)) ==
 	INVALID_HANDLE_VALUE)
@@ -2012,46 +2023,40 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
       goto error;
     }
 
-    sock= -1;
-
     /* We only look at the first item (something to think about changing in the future)
*/
     t_res= res_lst; 
     {
-      if ((sock= socket(t_res->ai_family, t_res->ai_socktype,
t_res->ai_protocol)) == SOCKET_ERROR)
+      my_socket sock= socket(t_res->ai_family, t_res->ai_socktype,
+                             t_res->ai_protocol);
+      if (sock == SOCKET_ERROR)
       {
         set_mysql_extended_error(mysql, CR_IPSOCK_ERROR, unknown_sqlstate,
                                  ER(CR_IPSOCK_ERROR), socket_errno);
-
         freeaddrinfo(res_lst);
         goto error;
       }
 
       net->vio= vio_new(sock, VIO_TYPE_TCPIP, VIO_BUFFERED_READ);
-      if (! net->vio ) 
+      if (! net->vio )
       {
         DBUG_PRINT("error",("Unknow protocol %d ", mysql->options.protocol));
         set_mysql_error(mysql, CR_CONN_UNKNOW_PROTOCOL, unknown_sqlstate);
-        close((int)sock);
-        sock=-1;
+        closesocket(sock);
         freeaddrinfo(res_lst);
-
-        goto error; 
+        goto error;
       }
 
-      if (my_connect(sock, t_res->ai_addr, t_res->ai_addrlen, 
-                     mysql->options.connect_timeout)) 
+      if (my_connect(sock, t_res->ai_addr, t_res->ai_addrlen,
+                     mysql->options.connect_timeout))
       {
         DBUG_PRINT("error",("Got error %d on connect to '%s'",socket_errno,
                             host));
         set_mysql_extended_error(mysql, CR_CONN_HOST_ERROR, unknown_sqlstate,
                                  ER(CR_CONN_HOST_ERROR), host, socket_errno);
         vio_delete(net->vio);
-        net->vio = 0;
-        close((int)sock);
-        sock=-1;
+        net->vio= 0;
         freeaddrinfo(res_lst);
-
-        goto error; 
+        goto error;
       }
     }
 
Thread
bk commit into 6.0 tree (msvensson:1.2530) BUG#34298msvensson7 Feb