Skip to content

Commit dc8cd8d

Browse files
authored
Merge pull request #219 from nielsdos/more-leak-fixes
Fix memory leaks when user functions misbehave and return different types
2 parents ce8b468 + 8834d99 commit dc8cd8d

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/ds/ds_htable.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,16 @@ static inline bool implements_hashable(zval *key) {
188188
#else
189189
zend_call_method_with_1_params(a, Z_OBJCE_P(a), NULL, "equals", &equals, b);
190190
#endif
191-
return Z_TYPE(equals) == IS_TRUE;
192-
}
191+
switch (Z_TYPE(equals)) {
192+
case IS_TRUE:
193+
return true;
194+
case IS_FALSE:
195+
return false;
196+
default:
197+
zval_ptr_dtor(&equals);
198+
return false;
199+
}
200+
}
193201
}
194202

195203
static inline bool key_is_identical(zval *key, zval *other)
@@ -544,7 +552,8 @@ static int user_compare_by_value(const void *a, const void *b)
544552
DSG(user_compare_fci).retval = &retval;
545553

546554
if (zend_call_function(&DSG(user_compare_fci), &DSG(user_compare_fci_cache)) == SUCCESS) {
547-
return zval_get_long(&retval);
555+
convert_to_long(&retval);
556+
return Z_LVAL(retval);
548557
}
549558

550559
return 0;
@@ -563,7 +572,8 @@ static int user_compare_by_key(const void *a, const void *b)
563572
DSG(user_compare_fci).retval = &retval;
564573

565574
if (zend_call_function(&DSG(user_compare_fci), &DSG(user_compare_fci_cache)) == SUCCESS) {
566-
return zval_get_long(&retval);
575+
convert_to_long(&retval);
576+
return Z_LVAL(retval);
567577
}
568578

569579
return 0;

0 commit comments

Comments
 (0)