Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

page fault when call free()

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

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: 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.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

636 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