@@ -689,6 +689,7 @@ static inline int php_tcp_sockop_bind(php_stream *stream, php_netstream_data_t *
689689 int portno , err ;
690690 long sockopts = STREAM_SOCKOP_NONE ;
691691 long linger = -1 ;
692+ void * option = NULL ;
692693 zval * tmpzval = NULL ;
693694
694695#ifdef AF_UNIX
@@ -750,25 +751,30 @@ static inline int php_tcp_sockop_bind(php_stream *stream, php_netstream_data_t *
750751
751752#ifdef SO_LINGER
752753 if (PHP_STREAM_CONTEXT (stream )
753- && (tmpzval = php_stream_context_get_option (PHP_STREAM_CONTEXT (stream ), "socket" , "so_linger " )) != NULL ) {
754+ && (tmpzval = php_stream_context_get_option (PHP_STREAM_CONTEXT (stream ), "socket" , "linger " )) != NULL ) {
754755 bool failed ;
755756 linger = parse_linger (tmpzval , & failed );
756757
757758 if (failed ) {
758759 if (xparam -> want_errortext ) {
759- xparam -> outputs .error_text = strpprintf (0 , "Invalid `so_linger` value" );
760+ xparam -> outputs .error_text = strpprintf (0 , "Invalid `linger` value" );
761+ }
762+ if (host ) {
763+ efree (host );
760764 }
761765 return -1 ;
762766 } else {
763767 sockopts |= STREAM_SOCKOP_SO_LINGER ;
764768 }
769+
770+ option = & linger ;
765771 }
766772#endif
767773
768774 sock -> socket = php_network_bind_socket_to_local_addr (host , portno ,
769775 stream -> ops == & php_stream_udp_socket_ops ? SOCK_DGRAM : SOCK_STREAM ,
770776 sockopts ,
771- linger ,
777+ option ,
772778 xparam -> want_errortext ? & xparam -> outputs .error_text : NULL ,
773779 & err
774780 );
@@ -790,6 +796,7 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_
790796 zval * tmpzval = NULL ;
791797 long sockopts = STREAM_SOCKOP_NONE ;
792798 long linger = -1 ;
799+ void * option = NULL ;
793800
794801#ifdef AF_UNIX
795802 if (stream -> ops == & php_stream_unix_socket_ops || stream -> ops == & php_stream_unixdg_socket_ops ) {
@@ -847,30 +854,38 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_
847854
848855#ifdef SO_LINGER
849856 if (PHP_STREAM_CONTEXT (stream )
850- && (tmpzval = php_stream_context_get_option (PHP_STREAM_CONTEXT (stream ), "socket" , "so_linger " )) != NULL ) {
857+ && (tmpzval = php_stream_context_get_option (PHP_STREAM_CONTEXT (stream ), "socket" , "linger " )) != NULL ) {
851858 bool failed ;
852859 linger = parse_linger (tmpzval , & failed );
853860
854861 if (failed ) {
855862 if (xparam -> want_errortext ) {
856- xparam -> outputs .error_text = strpprintf (0 , "Invalid `so_linger` value" );
863+ xparam -> outputs .error_text = strpprintf (0 , "Invalid `linger` value" );
864+ }
865+ if (host ) {
866+ efree (host );
867+ }
868+ if (bindto ) {
869+ efree (bindto );
857870 }
858871 return -1 ;
859872 } else {
860873 sockopts |= STREAM_SOCKOP_SO_LINGER ;
861874 }
875+
876+ option = & linger ;
862877 }
863878#endif
864879
865880 if (stream -> ops != & php_stream_udp_socket_ops /* TCP_NODELAY is only applicable for TCP */
866881#ifdef AF_UNIX
867- && stream -> ops != & php_stream_unix_socket_ops
868- && stream -> ops != & php_stream_unixdg_socket_ops
882+ && stream -> ops != & php_stream_unix_socket_ops
883+ && stream -> ops != & php_stream_unixdg_socket_ops
869884#endif
870- && PHP_STREAM_CONTEXT (stream )
871- && (tmpzval = php_stream_context_get_option (PHP_STREAM_CONTEXT (stream ), "socket" , "tcp_nodelay" )) != NULL
872- && zend_is_true (tmpzval )
873- ) {
885+ && PHP_STREAM_CONTEXT (stream )
886+ && (tmpzval = php_stream_context_get_option (PHP_STREAM_CONTEXT (stream ), "socket" , "tcp_nodelay" )) != NULL
887+ && zend_is_true (tmpzval )
888+ ) {
874889 sockopts |= STREAM_SOCKOP_TCP_NODELAY ;
875890 }
876891
@@ -887,7 +902,7 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_
887902 bindto ,
888903 bindport ,
889904 sockopts ,
890- linger
905+ option
891906 );
892907
893908 ret = sock -> socket == -1 ? -1 : 0 ;
0 commit comments