Solved

page fault when call free()

Posted on 1998-09-25
2
220 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

729 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