--=-nLp1AKiTuF74/TYUwQzJ
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

What should happen with the transport argument to snmp_sess_add_ex if
the creation of the session fails?

Today the code says that

* If the return on line 1577 or 1583 is taken then the transport
stays alive.
* If the return on line 1603 or 1611 is taken then the transport
is deleted.

Now, this means that a function calling snmp_sess_add_ex can't know if
the transport is live if there is a NULL return value.

I thus propose the attached patch that clarifies the semantics to be
that snmp_sess_add_ex always take ownership of the transport argument.

The reason I am pushing this one is that the resolution of it affects
how #1620424 should be solved.

/MF

--=-nLp1AKiTuF74/TYUwQzJ
Content-Disposition: attachment; filename=snmp_sess_add_ex-consistent-delete
Content-Type: text/x-patch; name=snmp_sess_add_ex-consistent-delete;
charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Index: snmplib/snmp_api.c
================================================== =================
--- snmplib/snmp_api.c (revision 16361)
+++ snmplib/snmp_api.c (working copy)
@@ -1566,27 +1566,32 @@ snmp_sess_add_ex(netsnmp_session * in_se
int (*frbuild) (netsnmp_session *, netsnmp_pdu *,
u_char **, size_t *, size_t *),
int (*fcheck) (u_char *, size_t),
netsnmp_pdu *(*fcreate_pdu) (netsnmp_transport *, void *,
size_t))
{
struct session_list *slp;

_init_snmp();

- if (in_session == NULL || transport == NULL) {
+ if (transport == NULL)
+ return NULL;
+
+ if (in_session == NULL) {
+ netsnmp_transport_free(transport);
return NULL;
}

DEBUGMSGTL(("snmp_sess_add", "fd %d\n", transport->sock));

if ((slp = snmp_sess_copy(in_session)) == NULL) {
+ netsnmp_transport_free(transport);
return (NULL);
}

slp->transport = transport;
slp->internal->hook_pre = fpre_parse;
slp->internal->hook_parse = fparse;
slp->internal->hook_post = fpost_parse;
slp->internal->hook_build = fbuild;
slp->internal->hook_realloc_build = frbuild;
slp->internal->check_packet = fcheck;
@@ -5561,23 +5566,20 @@ _sess_read(void *sessp, fd_set * fdset,
nslp->next = Sessions;
Sessions = nslp;
/*
* Tell the new session about its existance if possible.
*/
DEBUGMSGTL(("sess_read",
"perform callback with op=CONNECT\n"));
(void)nslp->session->callback(NETSNMP_CALLBACK_OP_CONNECT,
nslp->session, 0, NULL,
sp->callback_magic);
- } else {
- new_transport->f_close(new_transport);
- netsnmp_transport_free(new_transport);
}
return 0;
} else {
sp->s_snmp_errno = SNMPERR_MALLOC;
sp->s_errno = errno;
snmp_set_detail(strerror(errno));
return -1;
}
} else {
sp->s_snmp_errno = SNMPERR_BAD_RECVFROM;

--=-nLp1AKiTuF74/TYUwQzJ
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
--=-nLp1AKiTuF74/TYUwQzJ
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/...et-snmp-coders

--=-nLp1AKiTuF74/TYUwQzJ--