Page MenuHomeFreeBSD

Use reallocf instead of malloc to fix leak with outbuf_pmap
ClosedPublic

Authored by ngie on May 22 2016, 6:47 PM.
Tags
None
Referenced Files
Unknown Object (File)
Jun 18 2024, 4:55 PM
Unknown Object (File)
Jun 18 2024, 4:28 PM
Unknown Object (File)
Apr 18 2024, 9:50 AM
Unknown Object (File)
Apr 18 2024, 8:30 AM
Unknown Object (File)
Mar 6 2024, 6:15 PM
Unknown Object (File)
Feb 28 2024, 10:49 AM
Unknown Object (File)
Feb 28 2024, 9:03 AM
Unknown Object (File)
Jan 10 2024, 1:36 AM

Details

Reviewers
markj
pfg
Summary

Use reallocf instead of malloc to fix leak with outbuf_pmap

The previous code overwrote outbuf_pmap's memory with malloc once per
loop iteration, which leaked its memory; use reallocf instead to ensure
that memory is properly free'd each loop iteration.

Add a outbuf_pmap = NULL in the failure case to avoid a double-free
at the bottom of the function.

Reported by: Coverity
CID: 1038776
MFC after: 1 week
Sponsored by: EMC / Isilon Storage Division

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 3891
Build 3934: arc lint + arc unit

Event Timeline

ngie retitled this revision from to Use reallocf instead of malloc to fix leak with outbuf_pmap.
ngie updated this object.
ngie edited the test plan for this revision. (Show Details)
ngie added subscribers: mohlrich_isilon.com, markj, pfg, bdrewery.
pfg added a reviewer: pfg.

Interesting. Looks good to me.

This revision is now accepted and ready to land.May 22 2016, 10:14 PM
markj added a reviewer: markj.

Looks ok to me from a correctness perspective.

lib/libc/rpc/clnt_bcast.c
350

The line break is kind of ugly. Maybe make the assignment and check separate statements?

351

We appear to already free outbuf_pmap at done_broad, so I don't see the need for reallocf()+pointer clear vs. just a realloc() call.

ngie marked an inline comment as done.May 24 2016, 5:37 AM
ngie added inline comments.
lib/libc/rpc/clnt_bcast.c
351

I agree in theory, but replacing realloc with reallocf would require adding more complexity to deal with temporary pointers and the like. This is a pretty easy way to do things, even if it duplicates in the pathological case..

lib/libc/rpc/clnt_bcast.c
351

Ok, I see what you mean. Ignore what I said.

ngie marked 3 inline comments as done.