We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

"zend_mm_heap corrupted" when using "exit;"

Hello!

Like the title says. I basically have a very simple RestResponse() to which I can setContent($content) and then run sendAndExit() which sends an application/json content header, echoes the content and then exits.

Problem is, the line "exit;", the final line in the sendAndExit()-method sometimes causes zend_mm_heap corrupted errors in Apache, and I have been unable to figure out why. It doesn't happen every time, but sometimes I make a change to the code and this error pops up.

I've been trying to find explanations to this issuer here and there, and basically, they all say whats obvious: the Zend Memory Manager memory heap has been corrupted and the response cannot be sent.

If I remove the exit; at the end of this function, the problem does not occur.

Has anyone experienced / solved this problem, and if so, how did you manage to solve it?

Thanks for your time.

Best regards, dimhoLt

This looks to me like you are trying to reinvent the wheel and having some troubles.

Have you looked into using a phalcon response? https://docs.phalcon.io/en/latest/api/Phalcon_Http_Response.html

$response = new Phalcon\Http\Response();
$response->setStatusCode(200, "OK");
$response->setContent("<html><body>Hello</body></html>");
$response->send();

From your description it sounds like you have created a more difficult abstraction then just using the tools availible. Let me know if this helps.

You may also want to look at how others have structured an API:

https://github.com/cmoore4/phalcon-rest

https://github.com/mikegioia/phalcon-boilerplate

Ive faced this issue and this is what you should do after upgrading. Assuming you install phalcon using brew, uninstall phalcon through brew and install phalcon using PECL command instead. This is what i did at my Mac. For some reason the phalcon repository for brew is not updated and needs to be rebuild.