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

Fix memory leak in get_input when getline fails #39

Merged
merged 1 commit into from
Mar 11, 2025

Conversation

EricccTaiwan
Copy link
Contributor

If getline() fails, we should free the pre-allocated line buffer to avoid memory leaks. If line is NULL, calling free(NULL) is safe according to the C99 specification (Section 7.20.3.2).

This ensures proper memory management in case of input failure.

C99 (7.20.3.2.2)

The free function causes the space pointed to by ptr to be deallocated, that is, made available for further allocation. If ptr is a null pointer, no action occurs.

If getline() fails, we should free the pre-allocated line buffer to
avoid memory leaks. If line is NULL, calling free(NULL) is safe
according to the C99 specification (Section 7.20.3.2).

This ensures proper memory management in case of input failure.

Co-authored-by: charliechiou <[email protected]>
@jserv jserv merged commit 6a3093b into jserv:main Mar 11, 2025
2 checks passed
@jserv
Copy link
Owner

jserv commented Mar 11, 2025

Thank @EricccTaiwan for contributing!

@EricccTaiwan EricccTaiwan deleted the add-free branch March 11, 2025 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants