Skip to content

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 <charlie910417@gmail.com>
@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