Skip to content

Commit e4a8437

Browse files
committed
fix these leaks.
1 parent f99e1eb commit e4a8437

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

ext/snmp/snmp.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,19 +728,22 @@ static bool php_snmp_parse_oid(
728728
zval new;
729729
ZVAL_COPY_VALUE(&new, tmp_type);
730730
if (!try_convert_to_string(&new)) {
731+
zend_string_release(tmp);
731732
php_free_objid_query(objid_query, oid_ht, value_str, value_ht, st);
732733
return false;
733734
}
734735
if (Z_STRLEN(new) != 1) {
735736
zend_value_error("Type must be a single character");
737+
zend_string_release(tmp);
736738
php_free_objid_query(objid_query, oid_ht, value_str, value_ht, st);
737739
return false;
738740
}
739741
pptr = Z_STRVAL(new);
740742
objid_query->vars[objid_query->count].type = *pptr;
741743
idx_type++;
742744
} else {
743-
php_error_docref(NULL, E_WARNING, "'%s': no type set", Z_STRVAL_P(tmp_oid));
745+
php_error_docref(NULL, E_WARNING, "'%s': no type set", ZSTR_VAL(tmp));
746+
zend_string_release(tmp);
744747
php_free_objid_query(objid_query, oid_ht, value_str, value_ht, st);
745748
return false;
746749
}
@@ -775,7 +778,7 @@ static bool php_snmp_parse_oid(
775778
objid_query->vars[objid_query->count].value = ZSTR_VAL(tmp);
776779
idx_value++;
777780
} else {
778-
php_error_docref(NULL, E_WARNING, "'%s': no value set", Z_STRVAL_P(tmp_oid));
781+
php_error_docref(NULL, E_WARNING, "'%s': no value set", ZSTR_VAL(tmp));
779782
php_free_objid_query(objid_query, oid_ht, value_str, value_ht, st);
780783
return false;
781784
}

ext/snmp/tests/gh16959.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ try {
2525

2626
try {
2727
snmp2_set($hostname, $communityWrite, $bad_object_ids, array(new stdClass()), array(null));
28+
} catch (Throwable $e) {
29+
echo $e->getMessage() . PHP_EOL;
30+
}
31+
try {
32+
snmp2_set($hostname, $communityWrite, $bad_object_ids, array("toolongtype"), array(null));
2833
} catch (Throwable $e) {
2934
echo $e->getMessage();
3035
}
@@ -55,3 +60,4 @@ array(4) {
5560
}
5661
Object of class stdClass could not be converted to string
5762
Object of class stdClass could not be converted to string
63+
Type must be a single character

0 commit comments

Comments
 (0)