Home > Enterprise >  malloc.cpp not found, header IS included
malloc.cpp not found, header IS included

Time:07-25

I am aware of this question and its solution. Its solution (to include two header files listed below) is already in the code, so the post was unhelpful relative to my program.


I am working on an MFC program, using an old version of ZLib, specifically its 2005 version.

To practice with the zipping library, I attempted to use it with a regular C console program and it worked successfully (it added files correctly to a zip file).

Now, I am trying to add it in my MFC program. When pressing a button, a function is called and one of its jobs is to add files to a zip file. The thing is, it DOES work, but ONLY when the Run button is pressed, leaving the program to run on its own. The file is compressed successfully in the correct .zip file... HOWEVER, the issue comes from when I add a breakpoint and step through the program in the debugger.

Upon reaching the line: buf = (void*)malloc(size_buf); (found in the CMiniZip::OpenZip(const char* sOutFn) function within minizip.cpp file, if that helps or matters), I come across an error malloc.cpp not found. Strange, as both <stdlib.h> and <malloc.h> are both included as mentioned in the solution of the question linked at the start of this post.

My confusion (and my question) comes from this: why will the program run and compress files as expected when pressing the Run button, but not run when stepping through the program with the help of a breakpoint and the debugger. And why do both these methods work just fine in a non-MFC C console program?

Note: The files I zip and the zip folder itself are not touched at all by me while stepping through the program. I am simply clicking the Step Into button with the debugger. AND, this issue did not show up when adding a breakpoint and stepping through the regular C (non-MFC) program.

I am using Visual Studio C 17 Professional.

Any insight is appreciated, thank you in advance ! :D

CodePudding user response:

Turns out there is no issue at all.

C console programs are different from MFC here. Stepping through that line in a console program is the same as stepping OVER that line in MFC.

In MFC, you are actually given the option of seeing the assembly or rather, disassembly, code, by clicking a Disassembly option in the bottom half of the "error" page.

There is not issue. The malloc function is simply hidden.

And it would be better to change that ancient malloc and free to new and delete.

  • Related