@@ -106,7 +106,8 @@ sxe_property_read(zval *object, zval *member TSRMLS_DC)
106
106
xmlAttrPtr attr ;
107
107
int counter = 0 ;
108
108
109
- MAKE_STD_ZVAL (return_value );
109
+ ALLOC_ZVAL (return_value );
110
+ return_value -> refcount = 0 ;
110
111
ZVAL_NULL (return_value );
111
112
112
113
name = Z_STRVAL_P (member );
@@ -121,9 +122,9 @@ sxe_property_read(zval *object, zval *member TSRMLS_DC)
121
122
APPEND_PREV_ELEMENT (counter , value );
122
123
123
124
MAKE_STD_ZVAL (value );
125
+ value -> refcount = 0 ;
124
126
contents = xmlNodeListGetString ((xmlDocPtr ) sxe -> document -> ptr , attr -> children , 1 );
125
127
ZVAL_STRING (value , contents , 0 );
126
-
127
128
APPEND_CUR_ELEMENT (counter , value );
128
129
}
129
130
attr = attr -> next ;
@@ -146,17 +147,19 @@ sxe_property_read(zval *object, zval *member TSRMLS_DC)
146
147
147
148
if (match_ns (sxe , node , name )) {
148
149
MAKE_STD_ZVAL (value );
149
- _node_as_zval (sxe , node -> parent , value );
150
+ _node_as_zval (sxe , node -> parent , value TSRMLS_CC );
151
+ value -> refcount = 0 ;
150
152
APPEND_CUR_ELEMENT (counter , value );
151
153
goto next_iter ;
152
154
}
153
155
}
154
156
155
157
if (!xmlStrcmp (node -> name , name )) {
156
158
APPEND_PREV_ELEMENT (counter , value );
157
-
159
+
158
160
MAKE_STD_ZVAL (value );
159
161
_node_as_zval (sxe , node , value TSRMLS_CC );
162
+ value -> refcount = 0 ;
160
163
161
164
APPEND_CUR_ELEMENT (counter , value );
162
165
}
@@ -167,6 +170,9 @@ sxe_property_read(zval *object, zval *member TSRMLS_DC)
167
170
168
171
/* Only one value found */
169
172
if (counter == 1 ) {
173
+ SEPARATE_ZVAL (& value );
174
+ zval_dtor (return_value );
175
+ FREE_ZVAL (return_value );
170
176
return_value = value ;
171
177
}
172
178
@@ -328,7 +334,8 @@ sxe_property_delete(zval *object, zval *member TSRMLS_DC)
328
334
while (attr ) {
329
335
anext = attr -> next ;
330
336
if (!xmlStrcmp (attr -> name , Z_STRVAL_P (member ))) {
331
- // free
337
+ xmlUnlinkNode ((xmlNodePtr ) attr );
338
+ xmlFreeProp (attr );
332
339
}
333
340
attr = anext ;
334
341
}
@@ -353,7 +360,7 @@ sxe_property_delete(zval *object, zval *member TSRMLS_DC)
353
360
/* {{{ _get_base_node_value()
354
361
*/
355
362
static void
356
- _get_base_node_value (xmlNodePtr node , zval * * value TSRMLS_CC )
363
+ _get_base_node_value (xmlNodePtr node , zval * * value TSRMLS_DC )
357
364
{
358
365
php_sxe_object * subnode ;
359
366
char * contents ;
@@ -364,6 +371,7 @@ _get_base_node_value(xmlNodePtr node, zval **value TSRMLS_CC)
364
371
contents = xmlNodeListGetString (node -> doc , node -> children , 1 );
365
372
if (contents ) {
366
373
ZVAL_STRING (* value , contents , 1 );
374
+ xmlFree (contents );
367
375
}
368
376
} else {
369
377
subnode = php_sxe_object_new (TSRMLS_C );
@@ -455,6 +463,7 @@ sxe_objects_compare(zval *object1, zval *object2 TSRMLS_DC)
455
463
} else {
456
464
return !(sxe1 -> node == sxe2 -> node );
457
465
}
466
+ return 1 ;
458
467
}
459
468
/* }}} */
460
469
@@ -525,9 +534,9 @@ simplexml_ce_xpath_search(INTERNAL_FUNCTION_PARAMETERS)
525
534
* to the parent node.
526
535
*/
527
536
if (result -> nodeTab [i ]-> type == XML_TEXT_NODE ) {
528
- _node_as_zval (sxe , result -> nodeTab [i ]-> parent , value );
537
+ _node_as_zval (sxe , result -> nodeTab [i ]-> parent , value TSRMLS_CC );
529
538
} else {
530
- _node_as_zval (sxe , result -> nodeTab [i ], value );
539
+ _node_as_zval (sxe , result -> nodeTab [i ], value TSRMLS_CC );
531
540
}
532
541
add_next_index_zval (return_value , value );
533
542
}
@@ -576,6 +585,7 @@ simplexml_ce_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type)
576
585
is_valid = xmlSchemaValidateDoc (vptr , (xmlDocPtr ) sxe -> document -> ptr );
577
586
xmlSchemaFree (sptr );
578
587
xmlSchemaFreeValidCtxt (vptr );
588
+ xmlSchemaFreeParserCtxt (parser );
579
589
580
590
if (is_valid ) {
581
591
RETURN_TRUE ;
@@ -683,7 +693,7 @@ static void
683
693
sxe_object_cast (zval * readobj , zval * writeobj , int type , int should_free TSRMLS_DC )
684
694
{
685
695
php_sxe_object * sxe ;
686
- char * contents ;
696
+ char * contents = NULL ;
687
697
688
698
sxe = php_sxe_fetch_object (readobj TSRMLS_CC );
689
699
@@ -699,6 +709,10 @@ sxe_object_cast(zval *readobj, zval *writeobj, int type, int should_free TSRMLS_
699
709
}
700
710
701
711
cast_object (writeobj , type , contents TSRMLS_CC );
712
+
713
+ if (contents ) {
714
+ xmlFree (contents );
715
+ }
702
716
}
703
717
/* }}} */
704
718
@@ -783,20 +797,25 @@ sxe_object_dtor(void *object, zend_object_handle handle TSRMLS_DC)
783
797
784
798
sxe = (php_sxe_object * ) object ;
785
799
800
+ zend_hash_destroy (sxe -> zo .properties );
786
801
FREE_HASHTABLE (sxe -> zo .properties );
787
802
788
- if (-- sxe -> document -> refcount > 0 ) {
789
- return ;
803
+ if (sxe -> document ) {
804
+ if (-- sxe -> document -> refcount == 0 ) {
805
+ if (sxe -> document -> ptr ) {
806
+ xmlFreeDoc (sxe -> document -> ptr );
807
+ }
808
+ efree (sxe -> document );
809
+ sxe -> document = NULL ;
810
+ xmlHashFree (sxe -> nsmap , _free_ns_entry );
811
+ }
790
812
}
791
- xmlFreeDoc (sxe -> document -> ptr );
792
- efree (sxe -> document );
793
-
813
+
794
814
if (sxe -> xpath ) {
795
815
xmlXPathFreeContext (sxe -> xpath );
796
816
}
797
817
798
- xmlHashFree (sxe -> nsmap , _free_ns_entry );
799
- zend_objects_destroy_object (object , handle TSRMLS_CC );
818
+ efree (object );
800
819
}
801
820
/* }}} */
802
821
@@ -811,6 +830,9 @@ php_sxe_object_new(TSRMLS_D)
811
830
intern -> zo .ce = sxe_class_entry ;
812
831
intern -> zo .in_get = 0 ;
813
832
intern -> zo .in_set = 0 ;
833
+ intern -> document = NULL ;
834
+ intern -> nsmap = NULL ;
835
+ intern -> xpath = NULL ;
814
836
815
837
ALLOC_HASHTABLE (intern -> zo .properties );
816
838
zend_hash_init (intern -> zo .properties , 0 , NULL , ZVAL_PTR_DTOR , 0 );
@@ -990,6 +1012,7 @@ PHP_MINIT_FUNCTION(simplexml)
990
1012
*/
991
1013
PHP_MSHUTDOWN_FUNCTION (simplexml )
992
1014
{
1015
+ xmlCleanupParser ();
993
1016
return SUCCESS ;
994
1017
}
995
1018
/* }}} */
0 commit comments