473,385 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

What is CrtIsValidHeapPointer(pUserData)

I am new to C programming language
i am trying to implement linked list using C
but i found that error CrtIsValidHeapPointer(pUserData)
i don't know what is it

my code
Expand|Select|Wrap|Line Numbers
  1. struct node
  2. {
  3.     int value;
  4.     struct node * next;
  5. };
  6.  
  7. void addNode(struct node * t)
  8. {
  9.     t->next = (struct node *)malloc(sizeof(struct node));
  10.     if(t->next != NULL)
  11.     {
  12.         (t->next)->value = 5;
  13.         (t->next)->next = NULL;
  14.     }
  15.     else
  16.     {
  17.        printf("FATAL ERROR NO MEMORY");
  18.     }
  19. }
  20.  
  21.  
  22. int main(array<System::String ^> ^args)
  23. {
  24.     struct node * p;
  25.     struct node head;
  26.     head.value = 1;
  27.     head.next = NULL;
  28.     p = & head;
  29.        addNode(p);
  30.     while(p != NULL)
  31.     {
  32.         printf("%d\n",(*p).value);
  33.         p = (*p).next;
  34.     }
  35.     p = &head;
  36.     free(p->next);
  37.     p->next = NULL;
  38.     free(p);
  39.     p = NULL;
  40.     return 0;
  41. }
  42.  
i know that there is lot of things that is not implemented efficiently but now i am focusing only on this error
thanks in advance
Jul 23 '09 #1
1 5577
Banfa
9,065 Expert Mod 8TB
You call free(p) but p has been set to &head and not malloced so you are trying to free memory that is not allocated on the heap and hence you get the error.
Jul 23 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Frank Neuhaus | last post by:
Hi Iam trying to make a class where you can register callbacks to member functions of other classes. I declared the functions I wish to use like this: void SetMouseProc(ONMOUSEPROC proc, void*...
1
by: Adam Clauss | last post by:
I have an unmanaged C++ library that I need to use through C#. I created a Managed C++ class library and through it wrote a wrapper class to call what I need. However, one of the methods (an...
2
by: Mark Olbert | last post by:
First off, the sympathy is for all you poor buggers out there who have to figure out how to marry Managed Extensions for C++ onto your legacy code. My condolences; my brief experience with the...
0
by: jiing | last post by:
When I execute my program (it's multithread and has COM and dll), there is an error message as follows: Program D:\dongle_1\TestAP\bin\Debug\TestAP.exe File: dbgheap.c Line: 1132 Expression:...
0
by: jiing | last post by:
When I execute my program (it's multithread and has COM and dll), there is an error message as follows: Program D:\dongle_1\TestAP\bin\Debug\TestAP.exe File: dbgheap.c Line: 1132 Expression:...
13
by: Schizoid Man | last post by:
Hi, I have defined a very simple class as follows. I initialize the CInventory object as: CInventory *itemInveotry; The program just performs two functions - it reads the total number of...
6
by: =?Utf-8?B?R29yZG8=?= | last post by:
Hello everyone, I've been trying for some time now to move to C++/CLI, but I have several large legacy C++ static libraries I need to use. When I set up a simple solution with a C++/CLI Winforms...
10
by: VanKha | last post by:
Hi everybody.Could you tell me why this code fragment won't work:(In brief, I declare an array of char *,and use a function to get value for these strings(char *)using dynamic allocation)...
3
by: dreiko466 | last post by:
(sorry about my english...) I am a newbie in C (3 month expierience) I have wrote a simple test programm in VS2005, what i do wrong?Please... In this programm i create a double linked list.Then ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.