Solved

page fault when call free()

Posted on 1998-09-25
2
204 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 100 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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 …
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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now