Crashing due to v3MP::I ?

I’ve got a multithreaded application which talks to multiple agents (switches, routers and other devices). Each device can be configured differently so when using SNMP v3 I can’t have a single USM as the same “user” might exist on different devices with entirely different authPriv values.

To avoid complexity, I am creating a unique v3MP per SNMP session. This works well and avoids any security clashes. However, we get random crashes in calls like EventListHolder::SNMPBlockForResponse() and when we debug we can see that this = 0x0 !?

My “fix” has been remove v3MP::I completely and initialise the v3MP in the Snmp constructor to nullptr and then call set_mpv3() explicitly … and now things no longer crash

The use of v3MP::I in a multithreaded programs seems flawed, especially as it is set to 0 when any v3MP() object is destroyed? If a program needs such a global then surely its pretty simple to create one and set it using set_mpv3() as needed? Or better yet, add a new constructor which allows the v3MP to passed into Snmp()

I will confess I don’t really understand why removing the v3MP::I stops my crashes as each Snmp object should still have its own reference. C++ isn’t my primary programming experience so I might well have missed something!

I am using SNMP++ 3.6.1 and I’ve seen crashes on Linux and Windows

Your change should not fix the crashes you are seeing. During creation of the Snmp object, the v3MP object is not used at all. Only the pointer of the last created v3MP object (or null if a v3MP object was just deleted) is used to set the member pointer in Snmp object. In both cases you have to call Snmp::set_mpv3() right after creation of the Snmp object, so the initial pointer value will be overwritten and will never be used.

When you see that this = 0x0, is this the pointer to the v3MP?

But I have to admit that it might be time to remove the v3MP::I variable, as most usages inside snmp++ and agent++ have been removed already.

Best regards,
Jochen