Skip to content

Commit dbed284

Browse files
author
Boris Lytochkin
committed
fixed typos in tests
ucd-snmp epoch is over, drop legacy memory allocation (non e*) tune 'buggy snmp_snprint_value' detection on some systems
1 parent b966897 commit dbed284

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

ext/snmp/config.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ if test "$PHP_SNMP" != "no"; then
6262
dnl Check for buggy snmp_snprint_value() (net-snmp BUGid 2027834)
6363
AC_CACHE_CHECK([for buggy snmp_snprint_value], ac_cv_buggy_snprint_value,[
6464
save_CFLAGS="$CFLAGS"
65-
CFLAGS="$CFLAGS -I${SNMP_PREFIX}/include"
65+
CFLAGS="$CFLAGS -I${SNMP_PREFIX}/include $SNMP_SHARED_LIBADD"
6666
AC_TRY_RUN( [
6767
#include <stdio.h>
6868
#include <stdlib.h>

ext/snmp/snmp.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -440,12 +440,20 @@ static PHP_GINIT_FUNCTION(snmp)
440440
}
441441
/* }}} */
442442

443+
#define PHP_SNMP_SESSION_FREE(a) { \
444+
if ((*session)->a) { \
445+
efree((*session)->a); \
446+
(*session)->a = NULL; \
447+
} \
448+
}
449+
443450
static void netsnmp_session_free(php_snmp_session **session)
444451
{
445452
if (*session) {
446-
if ((*session)->peername) {
447-
efree((*session)->peername);
448-
}
453+
PHP_SNMP_SESSION_FREE(peername);
454+
PHP_SNMP_SESSION_FREE(community);
455+
PHP_SNMP_SESSION_FREE(securityName);
456+
PHP_SNMP_SESSION_FREE(contextEngineID);
449457
efree(*session);
450458
*session = NULL;
451459
}
@@ -1115,11 +1123,11 @@ static int netsnmp_session_init(php_snmp_session **session_p, int version, char
11151123

11161124
if (version == SNMP_VERSION_3) {
11171125
/* Setting the security name. */
1118-
session->securityName = strdup(community);
1126+
session->securityName = estrdup(community);
11191127
session->securityNameLen = strlen(session->securityName);
11201128
} else {
11211129
session->authenticator = NULL;
1122-
session->community = (u_char *)community;
1130+
session->community = (u_char *)estrdup(community);
11231131
session->community_len = strlen(community);
11241132
}
11251133

@@ -1222,20 +1230,20 @@ static int netsnmp_session_gen_sec_key(struct snmp_session *s, char *pass TSRMLS
12221230
static int netsnmp_session_set_contextEngineID(struct snmp_session *s, char * contextEngineID TSRMLS_DC)
12231231
{
12241232
size_t ebuf_len = 32, eout_len = 0;
1225-
u_char *ebuf = (u_char *) malloc(ebuf_len); /* memory freed by SNMP library, malloc NOT emalloc */
1233+
u_char *ebuf = (u_char *) emalloc(ebuf_len);
12261234

12271235
if (ebuf == NULL) {
12281236
php_error_docref(NULL TSRMLS_CC, E_WARNING, "malloc failure setting contextEngineID");
12291237
return (-1);
12301238
}
12311239
if (!snmp_hex_to_binary(&ebuf, &ebuf_len, &eout_len, 1, contextEngineID)) {
12321240
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Bad engine ID value '%s'", contextEngineID);
1233-
free(ebuf);
1241+
efree(ebuf);
12341242
return (-1);
12351243
}
12361244

12371245
if (s->contextEngineID) {
1238-
free(s->contextEngineID);
1246+
efree(s->contextEngineID);
12391247
}
12401248

12411249
s->contextEngineID = ebuf;

ext/snmp/tests/snmp-object-errno-errstr.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
OO API: getErrno & getError functions
2+
OO API: getErrno & getError methods
33
--CREDITS--
44
Boris Lytochkin
55
--SKIPIF--

ext/snmp/tests/wrong_hostname.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Generic timeout (wrong community)
2+
Wrong hostname
33
--CREDITS--
44
Boris Lytochkin
55
--SKIPIF--

0 commit comments

Comments
 (0)