@@ -689,6 +689,7 @@ static inline int php_tcp_sockop_bind(php_stream *stream, php_netstream_data_t *
689
689
int portno , err ;
690
690
long sockopts = STREAM_SOCKOP_NONE ;
691
691
long linger = -1 ;
692
+ void * option = NULL ;
692
693
zval * tmpzval = NULL ;
693
694
694
695
#ifdef AF_UNIX
@@ -750,25 +751,30 @@ static inline int php_tcp_sockop_bind(php_stream *stream, php_netstream_data_t *
750
751
751
752
#ifdef SO_LINGER
752
753
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 ) {
754
755
bool failed ;
755
756
linger = parse_linger (tmpzval , & failed );
756
757
757
758
if (failed ) {
758
759
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 );
760
764
}
761
765
return -1 ;
762
766
} else {
763
767
sockopts |= STREAM_SOCKOP_SO_LINGER ;
764
768
}
769
+
770
+ option = & linger ;
765
771
}
766
772
#endif
767
773
768
774
sock -> socket = php_network_bind_socket_to_local_addr (host , portno ,
769
775
stream -> ops == & php_stream_udp_socket_ops ? SOCK_DGRAM : SOCK_STREAM ,
770
776
sockopts ,
771
- linger ,
777
+ option ,
772
778
xparam -> want_errortext ? & xparam -> outputs .error_text : NULL ,
773
779
& err
774
780
);
@@ -790,6 +796,7 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_
790
796
zval * tmpzval = NULL ;
791
797
long sockopts = STREAM_SOCKOP_NONE ;
792
798
long linger = -1 ;
799
+ void * option = NULL ;
793
800
794
801
#ifdef AF_UNIX
795
802
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_
847
854
848
855
#ifdef SO_LINGER
849
856
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 ) {
851
858
bool failed ;
852
859
linger = parse_linger (tmpzval , & failed );
853
860
854
861
if (failed ) {
855
862
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 );
857
870
}
858
871
return -1 ;
859
872
} else {
860
873
sockopts |= STREAM_SOCKOP_SO_LINGER ;
861
874
}
875
+
876
+ option = & linger ;
862
877
}
863
878
#endif
864
879
865
880
if (stream -> ops != & php_stream_udp_socket_ops /* TCP_NODELAY is only applicable for TCP */
866
881
#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
869
884
#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
+ ) {
874
889
sockopts |= STREAM_SOCKOP_TCP_NODELAY ;
875
890
}
876
891
@@ -887,7 +902,7 @@ static inline int php_tcp_sockop_connect(php_stream *stream, php_netstream_data_
887
902
bindto ,
888
903
bindport ,
889
904
sockopts ,
890
- linger
905
+ option
891
906
);
892
907
893
908
ret = sock -> socket == -1 ? -1 : 0 ;
0 commit comments