Skip to content

Commit 6c15125

Browse files
committed
a
1 parent 0ac4e4b commit 6c15125

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

ext/snmp/snmp.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -630,12 +630,13 @@ static void php_snmp_zend_string_release_from_char_pointer(char *ptr) {
630630
zend_string_release((zend_string*) (ptr - XtOffsetOf(zend_string, val)));
631631
}
632632

633-
static void php_free_objid_query(struct objid_query *objid_query, zend_string* oid_str, int st) {
634-
if (oid_str && (st & SNMP_CMD_SET)) {
635-
php_snmp_zend_string_release_from_char_pointer(objid_query->vars[0].value);
636-
} else {
633+
static void php_free_objid_query(struct objid_query *objid_query, zend_string* oid_str, zend_string *type_str, int st) {
634+
if (!oid_str) {
637635
for (int i = 0; i < objid_query->count; i ++) {
638636
snmpobjarg *arg = &objid_query->vars[i];
637+
if ((st & SNMP_CMD_SET) && !type_str) {
638+
php_snmp_zend_string_release_from_char_pointer(&arg->type);
639+
}
639640
php_snmp_zend_string_release_from_char_pointer(arg->oid);
640641
}
641642
}
@@ -784,14 +785,14 @@ static bool php_snmp_parse_oid(
784785
if (st & SNMP_CMD_WALK) {
785786
if (objid_query->count > 1) {
786787
php_snmp_error(object, PHP_SNMP_ERRNO_OID_PARSING_ERROR, "Multi OID walks are not supported!");
787-
php_free_objid_query(objid_query, oid_str, st);
788+
php_free_objid_query(objid_query, oid_str, type_str, st);
788789
return false;
789790
}
790791
objid_query->vars[0].name_length = MAX_NAME_LEN;
791792
if (strlen(objid_query->vars[0].oid)) { /* on a walk, an empty string means top of tree - no error */
792793
if (!snmp_parse_oid(objid_query->vars[0].oid, objid_query->vars[0].name, &(objid_query->vars[0].name_length))) {
793794
php_snmp_error(object, PHP_SNMP_ERRNO_OID_PARSING_ERROR, "Invalid object identifier: %s", objid_query->vars[0].oid);
794-
php_free_objid_query(objid_query, oid_str, st);
795+
php_free_objid_query(objid_query, oid_str, type_str, st);
795796
return false;
796797
}
797798
} else {
@@ -803,7 +804,7 @@ static bool php_snmp_parse_oid(
803804
objid_query->vars[objid_query->offset].name_length = MAX_OID_LEN;
804805
if (!snmp_parse_oid(objid_query->vars[objid_query->offset].oid, objid_query->vars[objid_query->offset].name, &(objid_query->vars[objid_query->offset].name_length))) {
805806
php_snmp_error(object, PHP_SNMP_ERRNO_OID_PARSING_ERROR, "Invalid object identifier: %s", objid_query->vars[objid_query->offset].oid);
806-
php_free_objid_query(objid_query, oid_str, st);
807+
php_free_objid_query(objid_query, oid_str, type_str, st);
807808
return false;
808809
}
809810
}
@@ -1280,12 +1281,12 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
12801281

12811282
if (session_less_mode) {
12821283
if (!netsnmp_session_init(&session, version, a1, a2, timeout, retries)) {
1283-
php_free_objid_query(&objid_query, oid_str, st);
1284+
php_free_objid_query(&objid_query, oid_str, type_str, st);
12841285
netsnmp_session_free(&session);
12851286
RETURN_FALSE;
12861287
}
12871288
if (version == SNMP_VERSION_3 && !netsnmp_session_set_security(session, a3, a4, a5, a6, a7, NULL, NULL)) {
1288-
php_free_objid_query(&objid_query, oid_str, st);
1289+
php_free_objid_query(&objid_query, oid_str, type_str, st);
12891290
netsnmp_session_free(&session);
12901291
/* Warning message sent already, just bail out */
12911292
RETURN_FALSE;
@@ -1296,7 +1297,7 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
12961297
session = snmp_object->session;
12971298
if (!session) {
12981299
zend_throw_error(NULL, "Invalid or uninitialized SNMP object");
1299-
php_free_objid_query(&objid_query, oid_str, st);
1300+
php_free_objid_query(&objid_query, oid_str, type_str, st);
13001301
RETURN_THROWS();
13011302
}
13021303

@@ -1330,7 +1331,7 @@ static void php_snmp(INTERNAL_FUNCTION_PARAMETERS, int st, int version)
13301331
netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OID_OUTPUT_FORMAT, glob_snmp_object.oid_output_format);
13311332
}
13321333

1333-
php_free_objid_query(&objid_query, oid_str, st);
1334+
php_free_objid_query(&objid_query, oid_str, type_str, st);
13341335
}
13351336
/* }}} */
13361337

0 commit comments

Comments
 (0)