Skip to content

Conversation

Serpentian
Copy link

@Serpentian Serpentian commented May 23, 2023

This patch replaces all occurrences of memory related functions with
xmalloc, xcalloc and xrealloc, making them to panic, when we fail to
allocate memory for them.

Closes #3

This patch adds xmalloc, xcalloc, xrealloc helper functions. Each of
them  calls the corresponding memory allocation function and exits with
error if it fails.

Handling malloc/mmap failures doesn't make much sense, because modern
OSs have quite lenient memory overcommit policies. If an application
tries to use more memory than there's available on the host, the OS
will do swapping and if that doesn't help, it will kill the
application. That's it. No graceful termination. No malloc/mmap
failure. Just SIGKILL.

Nevertheless, we diligently strive to bail out gracefully in case
malloc returns NULL even though all the code written for handling those
failures is never executed (see the previous paragraph) hence is
untested and likely to have numerous bugs lurking in it. So, let's
just panic on malloc failure.

Part of #3
@Serpentian Serpentian marked this pull request as ready for review May 24, 2023 07:51
@Serpentian Serpentian requested a review from olegrok May 24, 2023 07:51
Copy link

@olegrok olegrok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your patch. In general LGTM but please consider two my comments.

This patch replaces all occurrences of memory related functions with
xmalloc, xcalloc and xrealloc, making them to panic, when we fail to
allocate memory for them.

Closes #3
@olegrok olegrok merged commit 0a7ebe3 into tarantool:master May 24, 2023
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.

Check all returned values from malloc calls.

2 participants