|
25 | 25 | #include <libxml/parserInternals.h>
|
26 | 26 | #include "zend_strtod.h"
|
27 | 27 | #include "zend_interfaces.h"
|
| 28 | +#include "zend_enum.h" |
28 | 29 |
|
29 | 30 | /* zval type decode */
|
30 | 31 | static zval *to_zval_double(zval* ret, encodeTypePtr type, xmlNodePtr data);
|
@@ -830,33 +831,34 @@ static zval *to_zval_hexbin(zval *ret, encodeTypePtr type, xmlNodePtr data)
|
830 | 831 | return ret;
|
831 | 832 | }
|
832 | 833 |
|
| 834 | +static zend_string *get_serialization_string_from_zval(zval *data) |
| 835 | +{ |
| 836 | + switch (Z_TYPE_P(data)) { |
| 837 | + default: |
| 838 | + return zval_get_string_func(data); |
| 839 | + } |
| 840 | +} |
| 841 | + |
833 | 842 | static xmlNodePtr to_xml_string(encodeTypePtr type, zval *data, int style, xmlNodePtr parent)
|
834 | 843 | {
|
835 | 844 | xmlNodePtr ret, text;
|
836 |
| - char *str; |
837 |
| - int new_len; |
838 | 845 |
|
839 | 846 | ret = xmlNewNode(NULL, BAD_CAST("BOGUS"));
|
840 | 847 | xmlAddChild(parent, ret);
|
841 | 848 | FIND_ZVAL_NULL(data, ret, style);
|
842 | 849 |
|
843 |
| - if (Z_TYPE_P(data) == IS_STRING) { |
844 |
| - str = estrndup(Z_STRVAL_P(data), Z_STRLEN_P(data)); |
845 |
| - new_len = Z_STRLEN_P(data); |
846 |
| - } else { |
847 |
| - zend_string *tmp = zval_get_string_func(data); |
848 |
| - str = estrndup(ZSTR_VAL(tmp), ZSTR_LEN(tmp)); |
849 |
| - new_len = ZSTR_LEN(tmp); |
850 |
| - zend_string_release_ex(tmp, 0); |
851 |
| - } |
| 850 | + zend_string *serialization = get_serialization_string_from_zval(data); |
| 851 | + char *str = ZSTR_VAL(serialization); |
| 852 | + size_t new_len = ZSTR_LEN(serialization); |
852 | 853 |
|
853 | 854 | if (SOAP_GLOBAL(encoding) != NULL) {
|
854 | 855 | xmlBufferPtr in = xmlBufferCreateStatic(str, new_len);
|
855 | 856 | xmlBufferPtr out = xmlBufferCreate();
|
856 | 857 | int n = xmlCharEncInFunc(SOAP_GLOBAL(encoding), out, in);
|
857 | 858 |
|
858 | 859 | if (n >= 0) {
|
859 |
| - efree(str); |
| 860 | + zend_string_release(serialization); |
| 861 | + serialization = NULL; |
860 | 862 | str = estrdup((char*)xmlBufferContent(out));
|
861 | 863 | new_len = n;
|
862 | 864 | }
|
@@ -907,7 +909,11 @@ static xmlNodePtr to_xml_string(encodeTypePtr type, zval *data, int style, xmlNo
|
907 | 909 |
|
908 | 910 | text = xmlNewTextLen(BAD_CAST(str), new_len);
|
909 | 911 | xmlAddChild(ret, text);
|
910 |
| - efree(str); |
| 912 | + if (serialization) { |
| 913 | + zend_string_release(serialization); |
| 914 | + } else { |
| 915 | + efree(str); |
| 916 | + } |
911 | 917 |
|
912 | 918 | if (style == SOAP_ENCODED) {
|
913 | 919 | set_ns_and_type(ret, type);
|
|
0 commit comments