Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attributes need reference counting #71

Open
ptesarik opened this issue Feb 24, 2023 · 1 comment
Open

Attributes need reference counting #71

ptesarik opened this issue Feb 24, 2023 · 1 comment
Assignees
Labels

Comments

@ptesarik
Copy link
Owner

Attributes can be used after deallocation (see e.g. osandov/drgn#280). That's because an explicit or implicit (like in the above case) reference may still exist after the attribute is cleared.

@ptesarik ptesarik self-assigned this Feb 24, 2023
@ptesarik ptesarik added the bug label Feb 24, 2023
@ptesarik
Copy link
Owner Author

Actually, this specific issue can be solved without reference counting, and that's going to be faster. I'll open another issue for that.

ptesarik added a commit that referenced this issue Dec 3, 2024
Modify kdump_attr_ref_get() to return data that is guaranteed to stay
valid. In particular:

- string attributes are duplicated
- blob and bitmap attributes increment their reference count

Of course, the caller should free these resources again when the data is no
longer needed. Add a kdump_attr_discard() function for that purpose.

Rationale

When used on a string, blob or bitmap attribute, kdump_get_attr(),
kdump_get_typed_attr() and derivatives will return a pointer to the
underlying data without any lifetime guarantees. Such pointers may become
dangling whenever the caller touches the containing dump file object. In
the extreme case, another thread may invalidate the pointer before it is
even returned to the caller.

However, most users are happy with these limitations, so keep the simple
API unchanged, only updating documentation.

There is also an attribute API based on references (kdump_attr_ref_t).
This API was primarily intended to allow iterating over attributes in a
thread-safe manner (although this is not yet fully implemented, cf. #71),
but it can be also used to get attribute values, see kdump_attr_ref_get().
Since this API is designed as thread-safe, it makes little sense to have a
thread-unsafe function to get attribute value.

It sounds fair that users of this API are now required to adapt their code
to avoid memory leaks.

Fixes: #82
Signed-off-by: Petr Tesarik <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant