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

  • SEARCH
  • Home
  • 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 1014645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:16:51+00:00 2026-05-16T10:16:51+00:00

I am allocating memory in a C program using malloc . It’s possible for

  • 0

I am allocating memory in a C program using malloc. It’s possible for my program to allocate more memory than the system has room for, at which point the program crashes. For my purposes it would be better if malloc would just return NULL (like it’s apparently supposed to), so I can catch the error. Instead what it does is it throws an error saying “No memory available to program now: unsafe to call malloc.” And crashes the program.

How can I fix this?

Edit: I know that the program is crashing by itself and not because I’m trying to reference a null pointer. The program never directly calls malloc, but instead calls a function I wrote that calls malloc and then checks to see if it returns NULL. It’s never saying that malloc returned NULL.

Edit 2: If it’s helpful, here is the complete error output:

Program received signal: “EXC_BAD_ACCESS”.
sharedlibrary apply-load-rules all
warning: Unable to restore previously selected frame.
Data Formatters temporarily unavailable, will re-try after a ‘continue’. (The program being debugged was signaled while in a function called from GDB.
GDB remains in the frame where the signal was received.
To change this behavior use “set unwindonsignal on”
Evaluation of the expression containing the function (dlopen) will be abandoned.)
No memory available to program now: unsafe to call malloc

  • 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-05-16T10:16:52+00:00Added an answer on May 16, 2026 at 10:16 am

    Once you scribble on the heap via buffer overruns, wild pointers or other bugs, malloc’s behavior becomes undefined and it could return anything.

    Malloc is simply a user-space library; there isn’t any magic contained within it. If I scribble all over your application’s linked list of customer names, you’ll get weird behavior when you later access that list. Malloc behaves in the same way, but since the use of malloc is distributed through the code, cause and effect have global reach.

    All of the answers are dancing around the fact that pointer errors are the single most prevalent source of defects in C code. You are lucky you are getting a SIGBUS which is the evidence of defect that may be widely separated from where and when the fault occurs. Use valgrind to help you find where the real defect is.

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

Sidebar

Related Questions

Which is preferable way to allocate memory for a function that is frequently allocating
I have trouble deallocating memory that I allocated using malloc. The program runs fine
We allocate memory in C using malloc and in C++ using new. I know
I have a problem with memory allocation using malloc. Here is a fragment from
This query is regarding allocation of memory using malloc . Generally what we say
I am curious to know if the allocating memory using a default new operator
I'm having problems allocating and deallocating my memory in a recursive C++ program. So
Description When allocating and deallocating randomly sized memory chunks with 4 or more threads
I developed a command-line (non GUI) C program on Linux using QT Creator, which
This is a sample code of my program. Here I am dynamically allocating 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.