Page MenuHomeFreeBSD

Simplify cleanup on failure in realpath(3).
ClosedPublic

Authored by kib on May 10 2017, 8:44 PM.
Tags
None
Referenced Files
F106198572: D10670.diff
Fri, Dec 27, 12:47 AM
Unknown Object (File)
Sat, Dec 21, 8:53 AM
Unknown Object (File)
Nov 17 2024, 2:11 AM
Unknown Object (File)
Oct 26 2024, 11:37 AM
Unknown Object (File)
Oct 26 2024, 11:37 AM
Unknown Object (File)
Oct 26 2024, 11:36 AM
Unknown Object (File)
Oct 26 2024, 11:36 AM
Unknown Object (File)
Oct 26 2024, 11:36 AM
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 Skipped
Unit
Tests Skipped
Build Status
Buildable 9271
Build 9725: CI src buildJenkins

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.