?
Solved

page fault when call free()

Posted on 1998-09-25
2
Medium Priority
?
222 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 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

Independent Software Vendors: 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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month9 days, 14 hours left to enroll

762 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