Skip to content

Commit 8834d99

Browse files
committed
Fix memory leaks when user functions misbehave and return different types
1 parent 4a62484 commit 8834d99

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)
@@ -540,7 +548,8 @@ static int user_compare_by_value(const void *a, const void *b)
540548
DSG(user_compare_fci).retval = &retval;
541549

542550
if (zend_call_function(&DSG(user_compare_fci), &DSG(user_compare_fci_cache)) == SUCCESS) {
543-
return zval_get_long(&retval);
551+
convert_to_long(&retval);
552+
return Z_LVAL(retval);
544553
}
545554

546555
return 0;
@@ -559,7 +568,8 @@ static int user_compare_by_key(const void *a, const void *b)
559568
DSG(user_compare_fci).retval = &retval;
560569

561570
if (zend_call_function(&DSG(user_compare_fci), &DSG(user_compare_fci_cache)) == SUCCESS) {
562-
return zval_get_long(&retval);
571+
convert_to_long(&retval);
572+
return Z_LVAL(retval);
563573
}
564574

565575
return 0;

0 commit comments

Comments
 (0)