Well I've finally found the origin of the crash and it had nothing to do
with net-snmp. There was an array overflow somewhere in the code and this
messed up the heap which made my program crash.

Although it's working as it should now, I still get the warning from
valgrind and I think it shouldn't be there. This is the code which causes
the valgrind warning:

void snmp::snmpget(string IpAddress, string OID, string community)
{
    struct snmp_session session;
    struct snmp_pdu *pdu;
    oid anOID[MAX_OID_LEN];
    size_t anOID_len = MAX_OID_LEN;
    struct timeval now;
    struct timezone tz;
    struct tm *tm;

      gettimeofday(&now, &tz);
      tm = localtime(&now.tv_sec);
      M_operation = NETSNMP_CALLBACK_OP_TIMED_OUT;

      snmp_sess_init( &session );
      session.peername = (char*)IpAddress.c_str();
      session.version = SNMP_VERSION_2c;
      session.community = (u_char*)community.c_str();
      session.community_len = strlen((char*)session.community);
      session.callback = asynch_response;
      session.callback_magic = (void *)this;
      session.timeout = 1000000; // 1 sec
      session.retries = 3;  // sometimes we might miss a packet, so let's
take 3 retries

      // Open the session
      ss = snmp_open(&session);
      if (!ss) {
        cout << "Snmpget : failed to open snmp session \n";
        cout << " time: " <<  tm->tm_hour << ":" << tm->tm_min << ":" <<
tm->tm_sec<< ":" << now.tv_usec;
        cout << " OID : " << OID << " host : " << IpAddress << " community :
" << community << "\n";
        return;
      }

      // define method (snmpget) and OID
      pdu = snmp_pdu_create(SNMP_MSG_GET);
      read_objid((char*)OID.c_str(), anOID, &anOID_len);
      snmp_add_null_var(pdu, anOID, anOID_len);

      // send the request
      if (!snmp_send(ss, pdu)) {
         cout << "Couldn't send snmpget \n";
         snmp_free_pdu(pdu);
      }
}


This is the valgrind warning I get:
==29356== Thread 1:
==29356== Syscall param socketcall.sendmsg(msg.msg_control) points to
uninitialised byte(s)
==29356==    at 0x40C9F78: sendmsg (in /lib/libpthread-0.10.so)
==29356==    by 0x80F6E88: snmp_sess_async_send (snmp_api.c:4892)
==29356==    by 0x80F73F3: snmp_send (snmp_api.c:4657)
==29356==    by 0x805D92A: snmp::snmpget(std::string, std::string,
std::string) (in /usr/bin/poller/poller)
==29356==    by 0x8056E1F: Poller::runPoller() (in /usr/bin/poller/poller)
==29356==    by 0x804E4E6: Config::RunNextPollers() (in
/usr/bin/poller/poller)
==29356==    by 0x804F303: Config::handle(OTC_Event*) (in
/usr/bin/poller/poller)
==29356==    by 0x80A5D78: OTC_EVAgent::filter(OTC_Event*) (in
/usr/bin/poller/poller)
==29356==    by 0x80A5D56: OTC_EVAgent::execute(OTC_Event*) (in
/usr/bin/poller/poller)
==29356==    by 0x80A5D34: OTC_EVAgent::accept(OTC_Event*) (in
/usr/bin/poller/poller)
==29356==    by 0x80A701C: OTC_Event::deliver(int) (in
/usr/bin/poller/poller)
==29356==    by 0x80A742E: OTC_EventJob::execute() (in
/usr/bin/poller/poller)
==29356==  Address 0xBEFE7F80 is on thread 1's stack

Is there something wrong in my code?

2008/6/3 Dave Shield <[EMAIL PROTECTED]>:

> 2008/6/3 Largo <[EMAIL PROTECTED]>:
> > - I have a function snmpget, where I call snmp_send.
> >   This is where I get the valgrind warning.
>
> What does this code look like?
>
> Dave
>
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
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

Reply via email to