@@ -694,6 +694,7 @@ static inline int php_tcp_sockop_bind(php_stream *stream, php_netstream_data_t *
694694 int portno , err ;
695695 long sockopts = STREAM_SOCKOP_NONE ;
696696 long linger = -1 ;
697+ void * option = NULL ;
697698 zval * tmpzval = NULL ;
698699
699700#ifdef AF_UNIX
@@ -755,25 +756,30 @@ static inline int php_tcp_sockop_bind(php_stream *stream, php_netstream_data_t *
755756
756757#ifdef SO_LINGER
757758 if (PHP_STREAM_CONTEXT (stream )
758- && (tmpzval = php_stream_context_get_option (PHP_STREAM_CONTEXT (stream ), "socket" , "so_linger " )) != NULL ) {
759+ && (tmpzval = php_stream_context_get_option (PHP_STREAM_CONTEXT (stream ), "socket" , "linger " )) != NULL ) {
759760 bool failed ;
760761 linger = parse_linger (tmpzval , & failed );
761762
762763 if (failed ) {
763764 if (xparam -> want_errortext ) {
764- xparam -> outputs .error_text = strpprintf (0 , "Invalid `so_linger` value" );
765+ xparam -> outputs .error_text = strpprintf (0 , "Invalid `linger` value" );
766+ }
767+ if (host ) {
768+ efree (host );
765769 }
766770 return -1 ;
767771 } else {
768772 sockopts |= STREAM_SOCKOP_SO_LINGER ;
769773 }
774+
775+ option = & linger ;
770776 }
771777#endif
772778
773779 sock -> socket = php_network_bind_socket_to_local_addr (host , portno ,
774780 stream -> ops == & php_stream_udp_socket_ops ? SOCK_DGRAM : SOCK_STREAM ,
775781 sockopts ,
776- linger ,
782+ option ,
777783 xparam -> want_errortext ? & xparam -> outputs .error_text : NULL ,
778784 & err
779785 );
@@ -795,6 +801,7 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_
795801 zval * tmpzval = NULL ;
796802 long sockopts = STREAM_SOCKOP_NONE ;
797803 long linger = -1 ;
804+ void * option = NULL ;
798805
799806#ifdef AF_UNIX
800807 if (stream -> ops == & php_stream_unix_socket_ops || stream -> ops == & php_stream_unixdg_socket_ops ) {
@@ -852,30 +859,38 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_
852859
853860#ifdef SO_LINGER
854861 if (PHP_STREAM_CONTEXT (stream )
855- && (tmpzval = php_stream_context_get_option (PHP_STREAM_CONTEXT (stream ), "socket" , "so_linger " )) != NULL ) {
862+ && (tmpzval = php_stream_context_get_option (PHP_STREAM_CONTEXT (stream ), "socket" , "linger " )) != NULL ) {
856863 bool failed ;
857864 linger = parse_linger (tmpzval , & failed );
858865
859866 if (failed ) {
860867 if (xparam -> want_errortext ) {
861- xparam -> outputs .error_text = strpprintf (0 , "Invalid `so_linger` value" );
868+ xparam -> outputs .error_text = strpprintf (0 , "Invalid `linger` value" );
869+ }
870+ if (host ) {
871+ efree (host );
872+ }
873+ if (bindto ) {
874+ efree (bindto );
862875 }
863876 return -1 ;
864877 } else {
865878 sockopts |= STREAM_SOCKOP_SO_LINGER ;
866879 }
880+
881+ option = & linger ;
867882 }
868883#endif
869884
870885 if (stream -> ops != & php_stream_udp_socket_ops /* TCP_NODELAY is only applicable for TCP */
871886#ifdef AF_UNIX
872- && stream -> ops != & php_stream_unix_socket_ops
873- && stream -> ops != & php_stream_unixdg_socket_ops
887+ && stream -> ops != & php_stream_unix_socket_ops
888+ && stream -> ops != & php_stream_unixdg_socket_ops
874889#endif
875- && PHP_STREAM_CONTEXT (stream )
876- && (tmpzval = php_stream_context_get_option (PHP_STREAM_CONTEXT (stream ), "socket" , "tcp_nodelay" )) != NULL
877- && zend_is_true (tmpzval )
878- ) {
890+ && PHP_STREAM_CONTEXT (stream )
891+ && (tmpzval = php_stream_context_get_option (PHP_STREAM_CONTEXT (stream ), "socket" , "tcp_nodelay" )) != NULL
892+ && zend_is_true (tmpzval )
893+ ) {
879894 sockopts |= STREAM_SOCKOP_TCP_NODELAY ;
880895 }
881896
@@ -892,7 +907,7 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_
892907 bindto ,
893908 bindport ,
894909 sockopts ,
895- linger
910+ option
896911 );
897912
898913 ret = sock -> socket == -1 ? -1 : 0 ;
0 commit comments