snmpset memory issue

Cathal McGlone <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <CAOJ101co+X-VY05SNVCX+hQ7OFAdDmaGkqmEOO4XCmMm67pf2w@mail.gmail.com>
hi there

hi there
I have been using snmpset in a Win10 command line to set variables in
example table netSnmpIETFWGTable and this works perfectly as follows:
C:\usr\bin>snmpset -v 2c -c nsCommStrRW 127.1.1.1
NET-SNMP-EXAMPLES-MIB::nsIETFWGChair1.\"wg1\" s jblog1
NET-SNMP-EXAMPLES-MIB::nsIETFWGChair2.\"wg1\" s jsnow1
NET-SNMP-EXAMPLES-MIB::nsIETFWGChair1."wg1" = STRING: "jblog1"
NET-SNMP-EXAMPLES-MIB::nsIETFWGChair2."wg1" = STRING: "jsnow1"
C:\usr\bin>snmptable -v 2c -c nsCommStrRW -Cc 12 -Cb -CB 127.1.1.1
NET-SNMP-EXAMPLES-MIB::netSnmpIETFWGTable
SNMP table: NET-SNMP-EXAMPLES-MIB::netSnmpIETFWGTable
        Name      Chair1      Chair2
       "wg1"    "jblog1"    "jsnow1"

I have a requirement however to run the set command within an application
and have done this by compiling the snmpset.c (net-snmp-5.8) source listing
into a test application as follows:
1) int snmpset(int argc, char *argv[]) //rename snmpset.c main function
2) static int quiet = 1;  //enable quiet mode
3) create a new c++ main driver function that runs snmpset loop:

#include <iostream>
#include <cstring>
#include <vector>
#include <sstream>
#include <chrono>
#include <thread>
extern "C"{
int snmpset(int argc, char *argv[]);
}
std::string int_to_string(int i){
 std::stringstream ss;
 ss << i;
 return (ss.str());
}
int main()
{
        int argc = 9, result = 0 ;
        std::string  comm, Wg, WgValue, Chair1, Chair2, Chair1Value,
Chair2Value;
        Wg  = "NET-SNMP-EXAMPLES-MIB::nsIETFWGName.\"wg1\"";
        char wg_array [Wg.size()+1];
        strcpy(wg_array, Wg.c_str());
        WgValue  = "wg1";
        char wgValue_array [comm.size()+1];
        strcpy(wgValue_array, WgValue.c_str());
        comm  = "nsCommStrRW";
        char comm_array [comm.size()+1];
        strcpy(comm_array, comm.c_str());
        char* snmp_set [] = {"snmpset.exe","-v", "2c", "-c", comm_array, "
127.1.1.1:161", wg_array, "s", wgValue_array};
        result = snmpset (argc, snmp_set );
        if (result){
            std::cout <<"snmpset fail: "<<result <<"\n";
        }
        Chair1  = "NET-SNMP-EXAMPLES-MIB::nsIETFWGChair1.\"wg1\"";
        char chair1_array [Chair1.size()+1];
        strcpy(chair1_array, Chair1.c_str());
        Chair2  = "NET-SNMP-EXAMPLES-MIB::nsIETFWGChair2.\"wg1\"";
        char chair2_array [Chair2.size()+1];
        strcpy(chair2_array, Chair2.c_str());
        argc = 12;
        while(true){
                for (int i =0; i<10000000; ++i)
                {
                comm  = "nsCommStrRW";
                char comm_array [comm.size()+1];
                strcpy(comm_array, comm.c_str());
                Chair1Value  = "jblog" + int_to_string(i);
                char Chair1Value_array [Chair1Value.size()+1];
                strcpy(Chair1Value_array, Chair1Value.c_str());
                Chair2Value  = "jsnow" + int_to_string(i);;
                char Chair2Value_array [Chair2Value.size()+1];
                strcpy(Chair2Value_array, Chair2Value.c_str());
                char* snmp_set [] = {"snmpset.exe","-v", "2c", "-c",
comm_array, "127.1.1.1:161", chair1_array, "s", Chair1Value_array,
chair2_array, "s", Chair2Value_array};
                result = snmpset (argc, snmp_set );
                    if (result){
                        std::cout <<"snmpset fail: "<<result <<"\n";
                        break;
                    }
                 std::this_thread::sleep_for(std::chrono::milliseconds(50));
                }
        }
    return 0;
}

The program updates Chair1 and Chair2 as expected as shown by issueing
consecutive snmptable commands:
C:\usr\bin>snmptable -v 2c -c nsCommStrRW -Cc 12 -Cb -CB 127.1.1.1
NET-SNMP-EXAMPLES-MIB::netSnmpIETFWGTable
SNMP table: NET-SNMP-EXAMPLES-MIB::netSnmpIETFWGTable
        Name      Chair1      Chair2
       "wg1"   "jblog88"   "jsnow88"
C:\usr\bin>snmptable -v 2c -c nsCommStrRW -Cc 12 -Cb -CB 127.1.1.1
NET-SNMP-EXAMPLES-MIB::netSnmpIETFWGTable
SNMP table: NET-SNMP-EXAMPLES-MIB::netSnmpIETFWGTable
        Name      Chair1      Chair2
       "wg1"  "jblog132"  "jsnow132"
C:\usr\bin>snmptable -v 2c -c nsCommStrRW -Cc 12 -Cb -CB 127.1.1.1
NET-SNMP-EXAMPLES-MIB::netSnmpIETFWGTable
SNMP table: NET-SNMP-EXAMPLES-MIB::netSnmpIETFWGTable
        Name      Chair1      Chair2
       "wg1"  "jblog626"  "jsnow626"

The problem however is that the application appears to consume memory each
time snmpset is called.
Here are some stats i have collected.
netSnmpIETFWGTable memory usage:
Time       Mem Usage(Kbytes)    Program Loops
09:00     1712                             0
09:30     2960                             25332
10:00     4624                             55858
10:30     6256                             85844
So after running for approx 1.5 hours the application had consumed approx
4MBytes
i need the application to run continuously therefore any memory used during
snmpset function call needs to be released on return.

Any help much appreciated.

Cathal

_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.