[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

page fault when call free()

Posted on 1998-09-25
2
Medium Priority
?
226 Views
Last Modified: 2013-11-19
Hi,

  I am using MSVC 5.0 and it is a Win32 console application. My program always got a page fault when it runs a while. After tracing the error, I finally find that it occurs when I call free(). However, this is very strange because this free() call is within a loop. It looks like this:

for(i=0;i<48;i++)  
  free(myPointer[i]);  // error occurs when i=18
free(myPointer);

The error occured when i = 18! I have checked myPointer's dimension and I am sure memory was successfully allocated to it. I would like to know what is the probable cause for this problem, or is it a bug of VC?

Any help is appreciated.

wyldsj
0
Comment
Question by:wyldsj
2 Comments
 
LVL 3

Accepted Solution

by:
Norbert earned 200 total points
ID: 1322614
First Using C++ You should use new instead of malloc
if you are using new you should use delete.

if it is always at position 18 have a look to the point where you allocate element 18 write the adress down
and compare it to the value that should be freed if it is not the same figure out where it is changed.

If it is the same assuming that your 48 allocations are made one after the other (no other allocation between) have a look to the point where element 17 is filled maybe inside this filling you cross the boundary

0
 

Expert Comment

by:umarama
ID: 1322615
Can you provide more details of your current code ? Maybe there is something you could have missed.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question