]> granicus.if.org Git - php/commitdiff
Changed socket_select to force reference copy, the older code would modify all references
authorJason Greene <jason@php.net>
Wed, 1 May 2002 04:46:59 +0000 (04:46 +0000)
committerJason Greene <jason@php.net>
Wed, 1 May 2002 04:46:59 +0000 (04:46 +0000)
@Fixed a bug in socket_select() that could cause unexpected behavior when using a statement
@ like $w=$e=array($sock);
@This change unfortunately prevents the use of constant values(NULL) for the socket array paramaters.
@Instead use a temporary variable or an expression with the leftmost member being a temporary variable.
@ ex. socket_select($w, $r, $e=NULL, 10);

Also fix small memory leak.

ext/sockets/sockets.c

index 52ddd50d87914a14e4f3ddb30b3aa1ce78200559..1d413fa019583a0ce4dd35aaf4e47fcf225577e7 100644 (file)
@@ -94,6 +94,9 @@ static int le_iov;
 static int le_socket;
 #define le_socket_name "Socket"
 
+static unsigned char first_through_third_args_force_ref[] =
+{3, BYREF_FORCE, BYREF_FORCE, BYREF_FORCE};
+
 static unsigned char second_and_third_args_force_ref[] =
 {3, BYREF_NONE, BYREF_FORCE, BYREF_FORCE};
 
@@ -115,7 +118,7 @@ function_entry sockets_functions[] = {
        PHP_FE(socket_iovec_fetch,              NULL)
        PHP_FE(socket_iovec_add,                NULL)
        PHP_FE(socket_iovec_delete,             NULL)
-       PHP_FE(socket_select,                   NULL)
+       PHP_FE(socket_select,                   first_through_third_args_force_ref)
        PHP_FE(socket_create,                   NULL)
        PHP_FE(socket_create_listen,    NULL)
        PHP_FE(socket_create_pair,              NULL)
@@ -487,6 +490,7 @@ int php_sock_array_from_fd_set(zval *sock_array, fd_set *fds TSRMLS_DC) {
 
        /* Destroy old array, add new one */
        zend_hash_destroy(Z_ARRVAL_P(sock_array));
+       efree(Z_ARRVAL_P(sock_array));
 
        zend_hash_internal_pointer_reset(new_hash);
        Z_ARRVAL_P(sock_array) = new_hash;