how to cleanly unregister a scalar (w/o memory leaks and such)?

Dirk Süsserott <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <[email protected]>
Hi together,

I've a question concerning the unregistration of scalars.
I use the following code to register an int32_t as a scalar:

------------- 8< -----------------------------------------------
int32_t *my_scalar = (int32_t*) malloc(sizeof(int32_t));

netsnmp_handler_registration *reg =
     netsnmp_create_handler_registration( "my_scalar",
                                          NULL,
                                          oid, oidlen, /* some OID */
                                          HANDLER_CAN_RONLY );

netsnmp_watcher_info *winfo =
     netsnmp_create_watcher_info( my_scalar,
                                  sizeof(*my_scalar),
                                  ASN_INTEGER,
                                  WATCHER_FIXED_SIZE );

netsnmp_register_watched_scalar( reg, winfo );
------------- 8< -----------------------------------------------

Now I want to de-register that scalar (e.g. because "my_scalar" gets freed).

If I just free the scalar (and do no unregistration stuff), the variable
still gets reported by snmpwalk. I know, it operates on "undefined"
memory then, and it's only a question of time when the application
crashes. Not what I want.

So I called
------------- 8< -----------------------------------------------
free( my_scalar );
netsnmp_unregister_handler( reg );
------------- 8< -----------------------------------------------

Works fine, the variable is no loger reported by snmpwalk.
But don't I have to de-allocate the watcher-info? And/or somehow
have to "undo" the call to netsnmp_register_watched_scalar()?
Do I have to call SNMP_FREE(reg) or SNMP_FREE(winfo) or does that
already take place behind the scenes?

I couldn't figure that out by reading the docs (and the sources
neither).

Any help appreciated.

Thanks in advance,
    Dirk





-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
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.