|
24 | 24 | #include <libxml/parserInternals.h>
|
25 | 25 | #include "zend_strtod.h"
|
26 | 26 | #include "zend_interfaces.h"
|
| 27 | +#include "zend_enum.h" |
27 | 28 |
|
28 | 29 | /* zval type decode */
|
29 | 30 | static zval *to_zval_double(zval* ret, encodeTypePtr type, xmlNodePtr data);
|
@@ -822,33 +823,34 @@ static zval *to_zval_hexbin(zval *ret, encodeTypePtr type, xmlNodePtr data)
|
822 | 823 | return ret;
|
823 | 824 | }
|
824 | 825 |
|
| 826 | +static zend_string *get_serialization_string_from_zval(zval *data) |
| 827 | +{ |
| 828 | + switch (Z_TYPE_P(data)) { |
| 829 | + default: |
| 830 | + return zval_get_string_func(data); |
| 831 | + } |
| 832 | +} |
| 833 | + |
825 | 834 | static xmlNodePtr to_xml_string(encodeTypePtr type, zval *data, int style, xmlNodePtr parent)
|
826 | 835 | {
|
827 | 836 | xmlNodePtr ret, text;
|
828 |
| - char *str; |
829 |
| - int new_len; |
830 | 837 |
|
831 | 838 | ret = xmlNewNode(NULL, BAD_CAST("BOGUS"));
|
832 | 839 | xmlAddChild(parent, ret);
|
833 | 840 | FIND_ZVAL_NULL(data, ret, style);
|
834 | 841 |
|
835 |
| - if (Z_TYPE_P(data) == IS_STRING) { |
836 |
| - str = estrndup(Z_STRVAL_P(data), Z_STRLEN_P(data)); |
837 |
| - new_len = Z_STRLEN_P(data); |
838 |
| - } else { |
839 |
| - zend_string *tmp = zval_get_string_func(data); |
840 |
| - str = estrndup(ZSTR_VAL(tmp), ZSTR_LEN(tmp)); |
841 |
| - new_len = ZSTR_LEN(tmp); |
842 |
| - zend_string_release_ex(tmp, 0); |
843 |
| - } |
| 842 | + zend_string *serialization = get_serialization_string_from_zval(data); |
| 843 | + char *str = ZSTR_VAL(serialization); |
| 844 | + size_t new_len = ZSTR_LEN(serialization); |
844 | 845 |
|
845 | 846 | if (SOAP_GLOBAL(encoding) != NULL) {
|
846 | 847 | xmlBufferPtr in = xmlBufferCreateStatic(str, new_len);
|
847 | 848 | xmlBufferPtr out = xmlBufferCreate();
|
848 | 849 | int n = xmlCharEncInFunc(SOAP_GLOBAL(encoding), out, in);
|
849 | 850 |
|
850 | 851 | if (n >= 0) {
|
851 |
| - efree(str); |
| 852 | + zend_string_release(serialization); |
| 853 | + serialization = NULL; |
852 | 854 | str = estrdup((char*)xmlBufferContent(out));
|
853 | 855 | new_len = n;
|
854 | 856 | }
|
@@ -899,7 +901,11 @@ static xmlNodePtr to_xml_string(encodeTypePtr type, zval *data, int style, xmlNo
|
899 | 901 |
|
900 | 902 | text = xmlNewTextLen(BAD_CAST(str), new_len);
|
901 | 903 | xmlAddChild(ret, text);
|
902 |
| - efree(str); |
| 904 | + if (serialization) { |
| 905 | + zend_string_release(serialization); |
| 906 | + } else { |
| 907 | + efree(str); |
| 908 | + } |
903 | 909 |
|
904 | 910 | if (style == SOAP_ENCODED) {
|
905 | 911 | set_ns_and_type(ret, type);
|
|
0 commit comments