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 8499891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:47:25+00:00 2026-06-11T00:47:25+00:00

I am writing a couple of PHP extensions as a personal project. (I used

  • 0

I am writing a couple of PHP extensions as a personal project. (I used to use C professionally a few decades ago for developing realtime and process control applications, so I am a bit paranoid about always checking memory allocator returns and ensuring that error paths don’t leak memory. But then came the world of C++ and exception handlers.) Now I have a simple Q:

Do I or don’t I need to do a NULL-check on buf after:

buf = emalloc(rec->len);

Normally on a FLOSS project, I would just use the existing source as a template to answer this sort of Q, but the PHP extensions are inconsistent. Statically analysing the complex C preprocessed code is impractical, and I can only easily test my own LAMP stack. Basicially as far as I can see emalloc code does invoke zend error routines on heap exhaustion, but the code then continues and returns 0. Some extension code cases do check for NULL return, yet you also find examples such as in PHPAPI void php_basename() in ext/standard/string.c such as:

if (p_ret) {
    ret = emalloc(len + 1);
    memcpy(ret, comp, len);
    ret[len] = '\0';
    *p_ret = ret;
}

which will generate a hard memory exception if emalloc does return rather than throwing a zend exception.

If anyone knows the official PHP developer answer, I’d be grateful for this. Thanks.

  • 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-11T00:47:27+00:00Added an answer on June 11, 2026 at 12:47 am

    The documentation clearly states:

    Note: Unlike their C standard library’s counterparts the Zend Engine’s memory management functions won’t return NULL in case of an problem while allocating the requested memory but bail out and terminate the current request.

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

Sidebar

Related Questions

I'm a totally newbie in class writing in PHP, started a couple days ago.
I will be writing my first daemon in php and I have a couple
I am writing code in embedded linux since last couple of years, I use
I used LaTeX for writing couple of white papers while I was in grad
I was writing some php code with a couple friends of mine a while
I am writing a web app in PHP that calls a couple API's. The
I am writing a couple of django apps which by design are coupled together.
I have been writing linear winforms for couple of months and now I am
I've been writing Java for the last couple of years , and now I've
I'm writing a web interface to MySQL that executes a couple queries and returns

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.