Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8146869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:09:13+00:00 2026-06-06T14:09:13+00:00

malloc is not guaranteed to return 0’ed memory. The conventional wisdom is not only

  • 0

malloc is not guaranteed to return 0’ed memory. The conventional wisdom is not only that, but that the contents of the memory malloc returns are actually non-deterministic, e.g. openssl used them for extra randomness.

However, as far as I know, malloc is built on top of brk/sbrk, which do “return” 0’ed memory. I can see why the contents of what malloc returns may be non-0, e.g. from previously free‘d memory, but why would they be non-deterministic in “normal” single-threaded software?

  1. Is the conventional wisdom really true (assuming the same binary and libraries)
  2. If so, Why?

Edit Several people answered explaining why the memory can be non-0, which I already explained in the question above. What I’m asking is why the program using the contents of what malloc returns may be non-deterministic, i.e. why it could have different behavior every time it’s run (assuming the same binary and libraries). Non-deterministic behavior is not implied by non-0’s. To put it differently: why it could have different contents every time the binary is run.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:09:15+00:00Added an answer on June 6, 2026 at 2:09 pm

    I think that the assumption that it is non-deterministic is plain wrong, particularly as you ask for a non-threaded context. (In a threaded context due to scheduling alea you could have some non-determinism).

    Just try it out. Create a sequential, deterministic application that

    • does a whole bunch of allocations
    • fills the memory with some pattern, eg fill it with the value of a counter
    • free every second of these allocations
    • newly allocate the same amount
    • run through these new allocations and register the value of the first byte in a file (as textual numbers one per line)

    run this program twice and register the result in two different files. My idea is that these files will be identical.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We know that malloc() and new operation allocate memory from heap dynamically, but where
I have read that free() generally does not return memory to the OS. Can
If you do not free memory that you malloc'd in a C program under
Somebody told me that allocating with malloc is not secure anymore, I'm not a
Unlike new and delete expressions, std::malloc does not call the constructor when memory for
Possible Duplicate: Malloc thread-safe? I heard that glibc malloc() was not thread safe, since
I am inspecting code that does not require explicitly casting result of malloc call
I am not particularly new to C/C++ but today I discovered some things that
When I free the malloc ed memory which are not allocated using malloc than
When using malloc, if it produces a core dump with the error: malloc(): memory

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.