Message ID | 20230801144209.557175-1-steved@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [1/2] rpcb_clnt.c: memory leak in destroy_addr | expand |
On 8/1/23 10:42 AM, Steve Dickson wrote: > From: Herb Wartens <wartens2@llnl.gov> > > Null pointers so they are not used again > > Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=2225226 > Signed-off-by: Steve Dickson <steved@redhat.com> Committed... (tag: libtirpc-1-3-4-rc2) steved > --- > src/rpcb_clnt.c | 20 +++++++++++++++----- > 1 file changed, 15 insertions(+), 5 deletions(-) > > diff --git a/src/rpcb_clnt.c b/src/rpcb_clnt.c > index d178d86..c0a9e12 100644 > --- a/src/rpcb_clnt.c > +++ b/src/rpcb_clnt.c > @@ -104,17 +104,27 @@ destroy_addr(addr) > { > if (addr == NULL) > return; > - if(addr->ac_host != NULL) > + if (addr->ac_host != NULL) { > free(addr->ac_host); > - if(addr->ac_netid != NULL) > + addr->ac_host = NULL; > + } > + if (addr->ac_netid != NULL) { > free(addr->ac_netid); > - if(addr->ac_uaddr != NULL) > + addr->ac_netid = NULL; > + } > + if (addr->ac_uaddr != NULL) { > free(addr->ac_uaddr); > - if(addr->ac_taddr != NULL) { > - if(addr->ac_taddr->buf != NULL) > + addr->ac_uaddr = NULL; > + } > + if (addr->ac_taddr != NULL) { > + if(addr->ac_taddr->buf != NULL) { > free(addr->ac_taddr->buf); > + addr->ac_taddr->buf = NULL; > + } > + addr->ac_taddr = NULL; > } > free(addr); > + addr = NULL; > } > > /*
diff --git a/src/rpcb_clnt.c b/src/rpcb_clnt.c index d178d86..c0a9e12 100644 --- a/src/rpcb_clnt.c +++ b/src/rpcb_clnt.c @@ -104,17 +104,27 @@ destroy_addr(addr) { if (addr == NULL) return; - if(addr->ac_host != NULL) + if (addr->ac_host != NULL) { free(addr->ac_host); - if(addr->ac_netid != NULL) + addr->ac_host = NULL; + } + if (addr->ac_netid != NULL) { free(addr->ac_netid); - if(addr->ac_uaddr != NULL) + addr->ac_netid = NULL; + } + if (addr->ac_uaddr != NULL) { free(addr->ac_uaddr); - if(addr->ac_taddr != NULL) { - if(addr->ac_taddr->buf != NULL) + addr->ac_uaddr = NULL; + } + if (addr->ac_taddr != NULL) { + if(addr->ac_taddr->buf != NULL) { free(addr->ac_taddr->buf); + addr->ac_taddr->buf = NULL; + } + addr->ac_taddr = NULL; } free(addr); + addr = NULL; } /*