Page MenuHomeFreeBSD

Simplify cleanup on failure in realpath(3).
ClosedPublic

Authored by kib on May 10 2017, 8:44 PM.
Tags
None
Referenced Files
Unknown Object (File)
Jan 6 2024, 8:56 AM
Unknown Object (File)
Dec 20 2023, 2:21 AM
Unknown Object (File)
Dec 14 2022, 10:59 PM
Subscribers

Details

Summary

If realpath() allocated memory for result and failed, the memory is freed in each place where return is performed. More, the function needs to track the allocation status, to not free user-supplied buffer.

Consolidate the memory handling in the wrapper, freeing the buffer if the actual worker failed.

This conflicts with the patch in PR 219154, I will pass the PR change first.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Do malloc() in realpath(), as before. Pass only 'resolved' to realpath1(), all logic to malloc and free is now located in realpath().

The conditional recording of "." path is now done always, in worst case of malloced result this two-bytes write is lost.

In principle, now realpath1() arguments could be qualified with restrict, but I decided no to, since 'sufficiently smart compiler' should be able to figure on its own, and restrict would make a difference only if compiler is smart enough.

Suggested by: emaste

This revision is now accepted and ready to land.May 15 2017, 3:33 PM
kib edited edge metadata.

Update after merge with r318298.

This revision now requires review to proceed.May 15 2017, 5:31 PM
This revision was automatically updated to reflect the committed changes.