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

libc/minimal: assorted fixes to malloc() and friends #33630

Merged
merged 1 commit into from
Mar 31, 2021

Conversation

npitre
Copy link
Collaborator

@npitre npitre commented Mar 23, 2021

  • When malloc() is called with a size of 0 we should not set errno
    to ENOMEM as there is no actual allocation failure in that case.
    This duplicates the realloc() behavior.

  • Put unlock_ret assignments on separate lines, otherwise gcc complains
    about unused variables when the tests on it are disabled.

  • There NULL return added in 952970d are completely pointless.
    First, there is no reason for sys_mutex_unlock() to fail, and even
    if it did, those returns would be blatent memory leaks. Remove them.
    No one should blindly modify code just to make static code
    analysers happy.

  • Replace all CHECKIF() by explicit assertion statements to uniformize
    those checks and drop the NULL returns entirely. We can't return
    anything in the free() case anyway, and there are no runtime
    conditions for sys_mutex_lock() to sometimes succeed and sometimes
    fail anyway.

Signed-off-by: Nicolas Pitre npitre@baylibre.com

- When malloc() is called with a size of 0 we should not set errno
  to ENOMEM as there is no actual allocation failure in that case.
  This duplicates the realloc() behavior.

- Put unlock_ret assignments on separate lines, otherwise gcc complains
  about unused variables when the tests on it are disabled.

- There NULL return added in 952970d are completely pointless.
  First, there is no reason for sys_mutex_unlock() to fail, and even
  if it did, those returns would be blatent memory leaks. Remove them.
  No one should blindly modify code just to make static code
  analysers happy.

- Replace all CHECKIF() by explicit assertion statements to uniformize
  those checks and drop the NULL returns entirely. We can't return
  anything in the free() case, and there are no runtime conditions
  for sys_mutex_lock() to sometimes succeed and sometimes fail anyway.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
@nashif nashif merged commit 7b6a4da into zephyrproject-rtos:master Mar 31, 2021
@npitre npitre deleted the memalloc2 branch March 31, 2021 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: C Library C Standard Library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants