Memory Leak in SNMP lib

I am attemting to use snmp to query a network printer for its status and its
appears that application built using the snmp libraries provided with the
TCP/IP development package grows in terms of memory usage.

I downloaded the snmpv1 sample from the contributed section and I modifed
the snmpget.c to loop continuly getting the stats and it too shows a memory
leak.

Can someone for QSSL please investigate to confirm or deny this. Thanks.

I start the modified snmpget as follows:
snmpget printerIP public
host.hrDevice.hrDeviceTable.hrDeviceEntry.hrDeviceStatus.1
host.hrDevice.hrPrinterTable.hrPrinterEntry.hrPrinterStatus.1
host.hrDevice.hrPrinterTable.hrPrinterEntry.hrPrinterDetectedErrorState.1

Here is the modified version of snmpget.c

/*

  • snmpget.c - send snmp GET requests to a network entity.

/
/
**********************************************************
Copyright 1988, 1989 by Carnegie Mellon University

All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of CMU not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
******************************************************************/
#include <sys/types.h>
#include <netinet/in.h>
#include <stdio.h>

#include <snmp/asn1.h>
#include <snmp/snmp.h>
#include <snmp/snmp_impl.h>
#include <snmp/asn1.h>
#include <snmp/snmp_api.h>
#include <snmp/snmp_client.h>

extern int errno;
int snmp_dump_packet = 0;

main(argc, argv)
int argc;
char *argv[];
{
struct snmp_session session, *ss;
struct snmp_pdu *pdu, *response;
struct variable_list *vars;
int arg;
char *gateway = NULL;
char *community = NULL;
int count, current_name = 0;
char *names[128];
oid name[MAX_NAME_LEN];
int name_length;
int status;

init_mib();
/*

  • usage: snmpget gateway-name community-name
    */
    for(arg = 1; arg < argc; arg++){
    if (argv[arg][0] == ‘-’){
    switch(argv[arg][1]){
    case ‘d’:
    snmp_dump_packet++;
    break;
    default:
    printf(“invalid option: -%c\n”, argv[arg][1]);
    break;
    }
    continue;
    }
    if (gateway == NULL){
    gateway = argv[arg];
    } else if (community == NULL){
    community = argv[arg];
    } else {
    names[current_name++] = argv[arg];
    }
    }

if (!(gateway && community && current_name > 0)){
printf(“usage: snmpget gateway-name community-name object-identifier
[object-identifier …]\n”);
exit(1);
}

bzero((char *)&session, sizeof(struct snmp_session));
session.peername = gateway;
session.community = (u_char *)community;
session.community_len = strlen((char *)community);
session.retries = SNMP_DEFAULT_RETRIES;
session.timeout = SNMP_DEFAULT_TIMEOUT;
session.authenticator = NULL;
snmp_synch_setup(&session);
ss = snmp_open(&session);
if (ss == NULL){
printf(“Couldn’t open snmp\n”);
exit(-1);
}

while( 1 )
{
pdu = snmp_pdu_create(GET_REQ_MSG);

for(count = 0; count < current_name; count++){
name_length = MAX_NAME_LEN;
if (!read_objid(names[count], name, &name_length)){
printf(“Invalid object identifier: %s\n”, names[count]);
}

snmp_add_null_var(pdu, name, name_length);
}

status = snmp_synch_response(ss, pdu, &response);
if (status == STAT_SUCCESS){
if (response->errstat == SNMP_ERR_NOERROR){
for(vars = response->variables; vars; vars = vars->next_variable)
print_variable(vars->name, vars->name_length, vars);
} else {
printf(“Error in packet.\nReason: %s\n”,
snmp_errstring(response->errstat));
if (response->errstat == SNMP_ERR_NOSUCHNAME){
printf(“This name doesn’t exist: “);
for(count = 1, vars = response->variables; vars && count !=
response->errindex;
vars = vars->next_variable, count++)
;
if (vars)
print_objid(vars->name, vars->name_length);
printf(”\n”);
}
}
// pdu should be freed by snmp_synch_response on success
// free the response
if (response)
snmp_free_pdu(response);

} else if (status == STAT_TIMEOUT){
printf(“No Response from %s\n”, gateway);
// pdu should be freed by snmp_synch_response on success
// but this is NOT success so free the pdu
// free the response
if( pdu )
snmp_free_pdu( pdu );
if (response)
snmp_free_pdu(response);
} else { /* status == STAT_ERROR */
printf(“An error occurred, Quitting\n”);
exit( EXIT_FAILURE );
}

sleep( 1 );
}
snmp_close(ss);
}

Does anyone care to comment? Has anyone used the SNMPV2 library provided
with the TCP/TK 4.25?

“Brown, Richard” <brownr@aecl.ca> wrote in message
news:aapco0$e7u$1@inn.qnx.com

I am attemting to use snmp to query a network printer for its status and
its
appears that application built using the snmp libraries provided with the
TCP/IP development package grows in terms of memory usage.

I downloaded the snmpv1 sample from the contributed section and I modifed
the snmpget.c to loop continuly getting the stats and it too shows a
memory
leak.

Can someone for QSSL please investigate to confirm or deny this. Thanks.

I start the modified snmpget as follows:
snmpget printerIP public
host.hrDevice.hrDeviceTable.hrDeviceEntry.hrDeviceStatus.1
host.hrDevice.hrPrinterTable.hrPrinterEntry.hrPrinterStatus.1
host.hrDevice.hrPrinterTable.hrPrinterEntry.hrPrinterDetectedErrorState.1

Here is the modified version of snmpget.c

/*

  • snmpget.c - send snmp GET requests to a network entity.

/
/
**********************************************************
Copyright 1988, 1989 by Carnegie Mellon University

All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of CMU not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
******************************************************************/
#include <sys/types.h
#include <netinet/in.h
#include <stdio.h

#include <snmp/asn1.h
#include <snmp/snmp.h
#include <snmp/snmp_impl.h
#include <snmp/asn1.h
#include <snmp/snmp_api.h
#include <snmp/snmp_client.h

extern int errno;
int snmp_dump_packet = 0;

main(argc, argv)
int argc;
char *argv[];
{
struct snmp_session session, *ss;
struct snmp_pdu *pdu, *response;
struct variable_list *vars;
int arg;
char *gateway = NULL;
char *community = NULL;
int count, current_name = 0;
char *names[128];
oid name[MAX_NAME_LEN];
int name_length;
int status;

init_mib();
/*

  • usage: snmpget gateway-name community-name
    */
    for(arg = 1; arg < argc; arg++){
    if (argv[arg][0] == ‘-’){
    switch(argv[arg][1]){
    case ‘d’:
    snmp_dump_packet++;
    break;
    default:
    printf(“invalid option: -%c\n”, argv[arg][1]);
    break;
    }
    continue;
    }
    if (gateway == NULL){
    gateway = argv[arg];
    } else if (community == NULL){
    community = argv[arg];
    } else {
    names[current_name++] = argv[arg];
    }
    }

if (!(gateway && community && current_name > 0)){
printf(“usage: snmpget gateway-name community-name object-identifier
[object-identifier …]\n”);
exit(1);
}

bzero((char *)&session, sizeof(struct snmp_session));
session.peername = gateway;
session.community = (u_char *)community;
session.community_len = strlen((char *)community);
session.retries = SNMP_DEFAULT_RETRIES;
session.timeout = SNMP_DEFAULT_TIMEOUT;
session.authenticator = NULL;
snmp_synch_setup(&session);
ss = snmp_open(&session);
if (ss == NULL){
printf(“Couldn’t open snmp\n”);
exit(-1);
}

while( 1 )
{
pdu = snmp_pdu_create(GET_REQ_MSG);

for(count = 0; count < current_name; count++){
name_length = MAX_NAME_LEN;
if (!read_objid(names[count], name, &name_length)){
printf(“Invalid object identifier: %s\n”, names[count]);
}

snmp_add_null_var(pdu, name, name_length);
}

status = snmp_synch_response(ss, pdu, &response);
if (status == STAT_SUCCESS){
if (response->errstat == SNMP_ERR_NOERROR){
for(vars = response->variables; vars; vars = vars->next_variable)
print_variable(vars->name, vars->name_length, vars);
} else {
printf(“Error in packet.\nReason: %s\n”,
snmp_errstring(response->errstat));
if (response->errstat == SNMP_ERR_NOSUCHNAME){
printf(“This name doesn’t exist: “);
for(count = 1, vars = response->variables; vars && count !=
response->errindex;
vars = vars->next_variable, count++)
;
if (vars)
print_objid(vars->name, vars->name_length);
printf(”\n”);
}
}
// pdu should be freed by snmp_synch_response on success
// free the response
if (response)
snmp_free_pdu(response);

} else if (status == STAT_TIMEOUT){
printf(“No Response from %s\n”, gateway);
// pdu should be freed by snmp_synch_response on success
// but this is NOT success so free the pdu
// free the response
if( pdu )
snmp_free_pdu( pdu );
if (response)
snmp_free_pdu(response);
} else { /* status == STAT_ERROR */
printf(“An error occurred, Quitting\n”);
exit( EXIT_FAILURE );
}

sleep( 1 );
}
snmp_close(ss);
}
\

Hi Richard,

I spoke with the developer about this issue and he will look into. I will let
you know when we have more information.

Regards,
Barry


Brown, Richard <brownr@aecl.ca> wrote:

I am attemting to use snmp to query a network printer for its status and its
appears that application built using the snmp libraries provided with the
TCP/IP development package grows in terms of memory usage.

I downloaded the snmpv1 sample from the contributed section and I modifed
the snmpget.c to loop continuly getting the stats and it too shows a memory
leak.

Can someone for QSSL please investigate to confirm or deny this. Thanks.

I start the modified snmpget as follows:
snmpget printerIP public
host.hrDevice.hrDeviceTable.hrDeviceEntry.hrDeviceStatus.1
host.hrDevice.hrPrinterTable.hrPrinterEntry.hrPrinterStatus.1
host.hrDevice.hrPrinterTable.hrPrinterEntry.hrPrinterDetectedErrorState.1

Here is the modified version of snmpget.c

/*

  • snmpget.c - send snmp GET requests to a network entity.

/
/
**********************************************************
Copyright 1988, 1989 by Carnegie Mellon University

All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of CMU not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
******************************************************************/
#include <sys/types.h
#include <netinet/in.h
#include <stdio.h

#include <snmp/asn1.h
#include <snmp/snmp.h
#include <snmp/snmp_impl.h
#include <snmp/asn1.h
#include <snmp/snmp_api.h
#include <snmp/snmp_client.h

extern int errno;
int snmp_dump_packet = 0;

main(argc, argv)
int argc;
char *argv[];
{
struct snmp_session session, *ss;
struct snmp_pdu *pdu, *response;
struct variable_list *vars;
int arg;
char *gateway = NULL;
char *community = NULL;
int count, current_name = 0;
char *names[128];
oid name[MAX_NAME_LEN];
int name_length;
int status;

init_mib();
/*

  • usage: snmpget gateway-name community-name
    */
    for(arg = 1; arg < argc; arg++){
    if (argv[arg][0] == ‘-’){
    switch(argv[arg][1]){
    case ‘d’:
    snmp_dump_packet++;
    break;
    default:
    printf(“invalid option: -%c\n”, argv[arg][1]);
    break;
    }
    continue;
    }
    if (gateway == NULL){
    gateway = argv[arg];
    } else if (community == NULL){
    community = argv[arg];
    } else {
    names[current_name++] = argv[arg];
    }
    }

if (!(gateway && community && current_name > 0)){
printf(“usage: snmpget gateway-name community-name object-identifier
[object-identifier …]\n”);
exit(1);
}

bzero((char *)&session, sizeof(struct snmp_session));
session.peername = gateway;
session.community = (u_char *)community;
session.community_len = strlen((char *)community);
session.retries = SNMP_DEFAULT_RETRIES;
session.timeout = SNMP_DEFAULT_TIMEOUT;
session.authenticator = NULL;
snmp_synch_setup(&session);
ss = snmp_open(&session);
if (ss == NULL){
printf(“Couldn’t open snmp\n”);
exit(-1);
}

while( 1 )
{
pdu = snmp_pdu_create(GET_REQ_MSG);

for(count = 0; count < current_name; count++){
name_length = MAX_NAME_LEN;
if (!read_objid(names[count], name, &name_length)){
printf(“Invalid object identifier: %s\n”, names[count]);
}

snmp_add_null_var(pdu, name, name_length);
}

status = snmp_synch_response(ss, pdu, &response);
if (status == STAT_SUCCESS){
if (response->errstat == SNMP_ERR_NOERROR){
for(vars = response->variables; vars; vars = vars->next_variable)
print_variable(vars->name, vars->name_length, vars);
} else {
printf(“Error in packet.\nReason: %s\n”,
snmp_errstring(response->errstat));
if (response->errstat == SNMP_ERR_NOSUCHNAME){
printf(“This name doesn’t exist: “);
for(count = 1, vars = response->variables; vars && count !=
response->errindex;
vars = vars->next_variable, count++)
;
if (vars)
print_objid(vars->name, vars->name_length);
printf(”\n”);
}
}
// pdu should be freed by snmp_synch_response on success
// free the response
if (response)
snmp_free_pdu(response);

} else if (status == STAT_TIMEOUT){
printf(“No Response from %s\n”, gateway);
// pdu should be freed by snmp_synch_response on success
// but this is NOT success so free the pdu
// free the response
if( pdu )
snmp_free_pdu( pdu );
if (response)
snmp_free_pdu(response);
} else { /* status == STAT_ERROR */
printf(“An error occurred, Quitting\n”);
exit( EXIT_FAILURE );
}

sleep( 1 );
}
snmp_close(ss);
}

Hi Richard,

What version of TCP/IP Runtime are you using? There was a memory leak problem
fixed in Patch C of the TCP/IP Runtime. If you aren’t using Patch C you can
download it from http://qdn.qnx.com/download/updates/tcpip/index.html. If you
are already using Patch C and still see the problem can you explain to us what
we should see when running your sample code, ie. how long does it have to run
before we should see the memory usage increase, etc. We have tried your sample
on a TCP/IP Patch C machine and the problem doesn’t seem to happen.


Regards,
Barry



Brown, Richard <brownr@aecl.ca> wrote:

I am attemting to use snmp to query a network printer for its status and its
appears that application built using the snmp libraries provided with the
TCP/IP development package grows in terms of memory usage.

I downloaded the snmpv1 sample from the contributed section and I modifed
the snmpget.c to loop continuly getting the stats and it too shows a memory
leak.

Can someone for QSSL please investigate to confirm or deny this. Thanks.

I start the modified snmpget as follows:
snmpget printerIP public
host.hrDevice.hrDeviceTable.hrDeviceEntry.hrDeviceStatus.1
host.hrDevice.hrPrinterTable.hrPrinterEntry.hrPrinterStatus.1
host.hrDevice.hrPrinterTable.hrPrinterEntry.hrPrinterDetectedErrorState.1

Here is the modified version of snmpget.c

/*

  • snmpget.c - send snmp GET requests to a network entity.

/
/
**********************************************************
Copyright 1988, 1989 by Carnegie Mellon University

All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of CMU not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
******************************************************************/
#include <sys/types.h
#include <netinet/in.h
#include <stdio.h

#include <snmp/asn1.h
#include <snmp/snmp.h
#include <snmp/snmp_impl.h
#include <snmp/asn1.h
#include <snmp/snmp_api.h
#include <snmp/snmp_client.h

extern int errno;
int snmp_dump_packet = 0;

main(argc, argv)
int argc;
char *argv[];
{
struct snmp_session session, *ss;
struct snmp_pdu *pdu, *response;
struct variable_list *vars;
int arg;
char *gateway = NULL;
char *community = NULL;
int count, current_name = 0;
char *names[128];
oid name[MAX_NAME_LEN];
int name_length;
int status;

init_mib();
/*

  • usage: snmpget gateway-name community-name
    */
    for(arg = 1; arg < argc; arg++){
    if (argv[arg][0] == ‘-’){
    switch(argv[arg][1]){
    case ‘d’:
    snmp_dump_packet++;
    break;
    default:
    printf(“invalid option: -%c\n”, argv[arg][1]);
    break;
    }
    continue;
    }
    if (gateway == NULL){
    gateway = argv[arg];
    } else if (community == NULL){
    community = argv[arg];
    } else {
    names[current_name++] = argv[arg];
    }
    }

if (!(gateway && community && current_name > 0)){
printf(“usage: snmpget gateway-name community-name object-identifier
[object-identifier …]\n”);
exit(1);
}

bzero((char *)&session, sizeof(struct snmp_session));
session.peername = gateway;
session.community = (u_char *)community;
session.community_len = strlen((char *)community);
session.retries = SNMP_DEFAULT_RETRIES;
session.timeout = SNMP_DEFAULT_TIMEOUT;
session.authenticator = NULL;
snmp_synch_setup(&session);
ss = snmp_open(&session);
if (ss == NULL){
printf(“Couldn’t open snmp\n”);
exit(-1);
}

while( 1 )
{
pdu = snmp_pdu_create(GET_REQ_MSG);

for(count = 0; count < current_name; count++){
name_length = MAX_NAME_LEN;
if (!read_objid(names[count], name, &name_length)){
printf(“Invalid object identifier: %s\n”, names[count]);
}

snmp_add_null_var(pdu, name, name_length);
}

status = snmp_synch_response(ss, pdu, &response);
if (status == STAT_SUCCESS){
if (response->errstat == SNMP_ERR_NOERROR){
for(vars = response->variables; vars; vars = vars->next_variable)
print_variable(vars->name, vars->name_length, vars);
} else {
printf(“Error in packet.\nReason: %s\n”,
snmp_errstring(response->errstat));
if (response->errstat == SNMP_ERR_NOSUCHNAME){
printf(“This name doesn’t exist: “);
for(count = 1, vars = response->variables; vars && count !=
response->errindex;
vars = vars->next_variable, count++)
;
if (vars)
print_objid(vars->name, vars->name_length);
printf(”\n”);
}
}
// pdu should be freed by snmp_synch_response on success
// free the response
if (response)
snmp_free_pdu(response);

} else if (status == STAT_TIMEOUT){
printf(“No Response from %s\n”, gateway);
// pdu should be freed by snmp_synch_response on success
// but this is NOT success so free the pdu
// free the response
if( pdu )
snmp_free_pdu( pdu );
if (response)
snmp_free_pdu(response);
} else { /* status == STAT_ERROR */
printf(“An error occurred, Quitting\n”);
exit( EXIT_FAILURE );
}

sleep( 1 );
}
snmp_close(ss);
}

Hi

I just want to confirm that the link you provided below is for TCP/IP V
4.25.

Why not use TCP/IP v 5.0 for QNX4? It IS much better. And it IS released.
It just doesn’t look like it.

“Operating System for Tech Supp” <os@qnx.com> wrote in message
news:abhciu$7eo$1@nntp.qnx.com

Hi Richard,

What version of TCP/IP Runtime are you using? There was a memory leak
problem
fixed in Patch C of the TCP/IP Runtime. If you aren’t using Patch C you
can
download it from > http://qdn.qnx.com/download/updates/tcpip/index.html> . If
you
are already using Patch C and still see the problem can you explain to us
what
we should see when running your sample code, ie. how long does it have to
run
before we should see the memory usage increase, etc. We have tried your
sample
on a TCP/IP Patch C machine and the problem doesn’t seem to happen.


Regards,
Barry



Brown, Richard <> brownr@aecl.ca> > wrote:
I am attemting to use snmp to query a network printer for its status and
its
appears that application built using the snmp libraries provided with
the
TCP/IP development package grows in terms of memory usage.

I downloaded the snmpv1 sample from the contributed section and I
modifed
the snmpget.c to loop continuly getting the stats and it too shows a
memory
leak.

Can someone for QSSL please investigate to confirm or deny this. Thanks.

I start the modified snmpget as follows:
snmpget printerIP public
host.hrDevice.hrDeviceTable.hrDeviceEntry.hrDeviceStatus.1
host.hrDevice.hrPrinterTable.hrPrinterEntry.hrPrinterStatus.1

host.hrDevice.hrPrinterTable.hrPrinterEntry.hrPrinterDetectedErrorState.1

Here is the modified version of snmpget.c

/*

  • snmpget.c - send snmp GET requests to a network entity.

/
/
**********************************************************
Copyright 1988, 1989 by Carnegie Mellon University

All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of CMU not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
******************************************************************/
#include <sys/types.h
#include <netinet/in.h
#include <stdio.h

#include <snmp/asn1.h
#include <snmp/snmp.h
#include <snmp/snmp_impl.h
#include <snmp/asn1.h
#include <snmp/snmp_api.h
#include <snmp/snmp_client.h

extern int errno;
int snmp_dump_packet = 0;

main(argc, argv)
int argc;
char *argv[];
{
struct snmp_session session, *ss;
struct snmp_pdu *pdu, *response;
struct variable_list *vars;
int arg;
char *gateway = NULL;
char *community = NULL;
int count, current_name = 0;
char *names[128];
oid name[MAX_NAME_LEN];
int name_length;
int status;

init_mib();
/*

  • usage: snmpget gateway-name community-name
    */
    for(arg = 1; arg < argc; arg++){
    if (argv[arg][0] == ‘-’){
    switch(argv[arg][1]){
    case ‘d’:
    snmp_dump_packet++;
    break;
    default:
    printf(“invalid option: -%c\n”, argv[arg][1]);
    break;
    }
    continue;
    }
    if (gateway == NULL){
    gateway = argv[arg];
    } else if (community == NULL){
    community = argv[arg];
    } else {
    names[current_name++] = argv[arg];
    }
    }

if (!(gateway && community && current_name > 0)){
printf(“usage: snmpget gateway-name community-name object-identifier
[object-identifier …]\n”);
exit(1);
}

bzero((char *)&session, sizeof(struct snmp_session));
session.peername = gateway;
session.community = (u_char *)community;
session.community_len = strlen((char *)community);
session.retries = SNMP_DEFAULT_RETRIES;
session.timeout = SNMP_DEFAULT_TIMEOUT;
session.authenticator = NULL;
snmp_synch_setup(&session);
ss = snmp_open(&session);
if (ss == NULL){
printf(“Couldn’t open snmp\n”);
exit(-1);
}

while( 1 )
{
pdu = snmp_pdu_create(GET_REQ_MSG);

for(count = 0; count < current_name; count++){
name_length = MAX_NAME_LEN;
if (!read_objid(names[count], name, &name_length)){
printf(“Invalid object identifier: %s\n”, names[count]);
}

snmp_add_null_var(pdu, name, name_length);
}

status = snmp_synch_response(ss, pdu, &response);
if (status == STAT_SUCCESS){
if (response->errstat == SNMP_ERR_NOERROR){
for(vars = response->variables; vars; vars = vars->next_variable)
print_variable(vars->name, vars->name_length, vars);
} else {
printf(“Error in packet.\nReason: %s\n”,
snmp_errstring(response->errstat));
if (response->errstat == SNMP_ERR_NOSUCHNAME){
printf(“This name doesn’t exist: “);
for(count = 1, vars = response->variables; vars && count !=
response->errindex;
vars = vars->next_variable, count++)
;
if (vars)
print_objid(vars->name, vars->name_length);
printf(”\n”);
}
}
// pdu should be freed by snmp_synch_response on success
// free the response
if (response)
snmp_free_pdu(response);

} else if (status == STAT_TIMEOUT){
printf(“No Response from %s\n”, gateway);
// pdu should be freed by snmp_synch_response on success
// but this is NOT success so free the pdu
// free the response
if( pdu )
snmp_free_pdu( pdu );
if (response)
snmp_free_pdu(response);
} else { /* status == STAT_ERROR */
printf(“An error occurred, Quitting\n”);
exit( EXIT_FAILURE );
}

sleep( 1 );
}
snmp_close(ss);
}
\

Sorry for the long delay I was away for a couple of weeks.

The memory still appears to leak even with TCPRT 4.25C. The following
packages are being used:
QNX RTOS 4.25E
TCPRT 4.25C
Watcom 10.6B
TCPTK 4.25B

If one adds a loop counter and disables the heap (_heapenable( 0 ) ) after
10 iterations then it should fail at about the 78th iteration.

It appears to be time sensitive because if I enable too many breakpoints
within the debugger it will live longer and potentially indefitinely. On
that note I am testing on a PII 350 MHz but I am able to see the failure on
a PII 450 MHz as well.


“Operating System for Tech Supp” <os@qnx.com> wrote in message
news:abhciu$7eo$1@nntp.qnx.com

Hi Richard,

What version of TCP/IP Runtime are you using? There was a memory leak
problem
fixed in Patch C of the TCP/IP Runtime. If you aren’t using Patch C you
can
download it from > http://qdn.qnx.com/download/updates/tcpip/index.html> . If
you
are already using Patch C and still see the problem can you explain to us
what
we should see when running your sample code, ie. how long does it have to
run
before we should see the memory usage increase, etc. We have tried your
sample
on a TCP/IP Patch C machine and the problem doesn’t seem to happen.


Regards,
Barry



Brown, Richard <> brownr@aecl.ca> > wrote:
I am attemting to use snmp to query a network printer for its status and
its
appears that application built using the snmp libraries provided with
the
TCP/IP development package grows in terms of memory usage.

I downloaded the snmpv1 sample from the contributed section and I
modifed
the snmpget.c to loop continuly getting the stats and it too shows a
memory
leak.

Can someone for QSSL please investigate to confirm or deny this. Thanks.

I start the modified snmpget as follows:
snmpget printerIP public
host.hrDevice.hrDeviceTable.hrDeviceEntry.hrDeviceStatus.1
host.hrDevice.hrPrinterTable.hrPrinterEntry.hrPrinterStatus.1

host.hrDevice.hrPrinterTable.hrPrinterEntry.hrPrinterDetectedErrorState.1

Here is the modified version of snmpget.c

/*

  • snmpget.c - send snmp GET requests to a network entity.

/
/
**********************************************************
Copyright 1988, 1989 by Carnegie Mellon University

All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of CMU not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
******************************************************************/
#include <sys/types.h
#include <netinet/in.h
#include <stdio.h

#include <snmp/asn1.h
#include <snmp/snmp.h
#include <snmp/snmp_impl.h
#include <snmp/asn1.h
#include <snmp/snmp_api.h
#include <snmp/snmp_client.h

extern int errno;
int snmp_dump_packet = 0;

main(argc, argv)
int argc;
char *argv[];
{
struct snmp_session session, *ss;
struct snmp_pdu *pdu, *response;
struct variable_list *vars;
int arg;
char *gateway = NULL;
char *community = NULL;
int count, current_name = 0;
char *names[128];
oid name[MAX_NAME_LEN];
int name_length;
int status;

init_mib();
/*

  • usage: snmpget gateway-name community-name
    */
    for(arg = 1; arg < argc; arg++){
    if (argv[arg][0] == ‘-’){
    switch(argv[arg][1]){
    case ‘d’:
    snmp_dump_packet++;
    break;
    default:
    printf(“invalid option: -%c\n”, argv[arg][1]);
    break;
    }
    continue;
    }
    if (gateway == NULL){
    gateway = argv[arg];
    } else if (community == NULL){
    community = argv[arg];
    } else {
    names[current_name++] = argv[arg];
    }
    }

if (!(gateway && community && current_name > 0)){
printf(“usage: snmpget gateway-name community-name object-identifier
[object-identifier …]\n”);
exit(1);
}

bzero((char *)&session, sizeof(struct snmp_session));
session.peername = gateway;
session.community = (u_char *)community;
session.community_len = strlen((char *)community);
session.retries = SNMP_DEFAULT_RETRIES;
session.timeout = SNMP_DEFAULT_TIMEOUT;
session.authenticator = NULL;
snmp_synch_setup(&session);
ss = snmp_open(&session);
if (ss == NULL){
printf(“Couldn’t open snmp\n”);
exit(-1);
}

while( 1 )
{
pdu = snmp_pdu_create(GET_REQ_MSG);

for(count = 0; count < current_name; count++){
name_length = MAX_NAME_LEN;
if (!read_objid(names[count], name, &name_length)){
printf(“Invalid object identifier: %s\n”, names[count]);
}

snmp_add_null_var(pdu, name, name_length);
}

status = snmp_synch_response(ss, pdu, &response);
if (status == STAT_SUCCESS){
if (response->errstat == SNMP_ERR_NOERROR){
for(vars = response->variables; vars; vars = vars->next_variable)
print_variable(vars->name, vars->name_length, vars);
} else {
printf(“Error in packet.\nReason: %s\n”,
snmp_errstring(response->errstat));
if (response->errstat == SNMP_ERR_NOSUCHNAME){
printf(“This name doesn’t exist: “);
for(count = 1, vars = response->variables; vars && count !=
response->errindex;
vars = vars->next_variable, count++)
;
if (vars)
print_objid(vars->name, vars->name_length);
printf(”\n”);
}
}
// pdu should be freed by snmp_synch_response on success
// free the response
if (response)
snmp_free_pdu(response);

} else if (status == STAT_TIMEOUT){
printf(“No Response from %s\n”, gateway);
// pdu should be freed by snmp_synch_response on success
// but this is NOT success so free the pdu
// free the response
if( pdu )
snmp_free_pdu( pdu );
if (response)
snmp_free_pdu(response);
} else { /* status == STAT_ERROR */
printf(“An error occurred, Quitting\n”);
exit( EXIT_FAILURE );
}

sleep( 1 );
}
snmp_close(ss);
}
\