473,324 Members | 2,179 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,324 software developers and data experts.

free(): invalid pointer:

Hello friends,

I'm getting a bizaare glibc error referencing free -- I malloc a
chunk of memory and then later when I try to free it is when the
program aborts. I've added some debug code to the source and find
that my pointer i get from malloc matches the one that I'm calling
free with -- and there is no possibility that have i have previously
freed the memory because there is only 1 free call in the entire
source (surrounded by debug printfs) so I don't know what is going on.
Any insight?

Thanks,
Mike

Sep 30 '07 #1
3 12995
On 30 Sep, 21:03, Cyron <mdigit...@yahoo.comwrote:
Hello friends,

I'm getting a bizaare glibc error referencing free -- I malloc a
chunk of memory and then later when I try to free it is when the
program aborts. I've added some debug code to the source and find
that my pointer i get from malloc matches the one that I'm calling
free with -- and there is no possibility that have i have previously
freed the memory because there is only 1 free call in the entire
source (surrounded by debug printfs) so I don't know what is going on.
Any insight?
Are you perhaps writing to memory just outside the memory you have
allocated?

Sep 30 '07 #2
Cyron wrote, On 30/09/07 21:03:
I'm getting a bizaare glibc error referencing free -- I malloc a
chunk of memory and then later when I try to free it is when the
program aborts. I've added some debug code to the source and find
<snip>

You are probably writing beyond the end or before the start of the
allocated space. If you can get the program down to a reasonably small
chunk of code that shows the problem we can take a look at it.
--
Flash Gordon
Sep 30 '07 #3
In article <11*********************@50g2000hsm.googlegroups.c om>,
Cyron <md*******@yahoo.comwrote:
I'm getting a bizaare glibc error referencing free -- I malloc a
chunk of memory and then later when I try to free it is when the
program aborts. I've added some debug code to the source and find
that my pointer i get from malloc matches the one that I'm calling
free with -- and there is no possibility that have i have previously
freed the memory because there is only 1 free call in the entire
source (surrounded by debug printfs) so I don't know what is going on.
You almost certainly have some kind of out-of-bounds pointer error.
Your first choice for finding such things, if you have one available,
is a memory-reference-checking tool such as valgrind. From your
reference to glibc, I assume you're using Linux, so valgrind should be
available. I find that 90% of the time it directs me straight to the
bug.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Sep 30 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Ramprasad A Padmanabhan | last post by:
Hello all, If I assign one pointer to another , I had assumed I can call them interchangably. I can explain by the example below. I am doing a malloc to char* a which is the same as char* b....
17
by: kj | last post by:
How can one test if a pointer has been "freed" (i.e. with free())? My naive assumption was that such a pointer would equal NULL, but not so. Thanks, kj -- NOTE: In my address everything...
86
by: Walter Roberson | last post by:
If realloc() finds it necessary to move the memory block, then does it free() the previously allocated block? The C89 standard has some reference to undefined behaviour if one realloc()'s memory...
13
by: santosh | last post by:
Hi, If I call free() with a uninitialised pointer, will the program state become undefined, or will free() return harmlessly? Incidentally, is there a way in Standard C to determine weather a...
3
by: Ramki | last post by:
How does free() , delete() works? If we allocate memory using the following statement int *p = malloc(100*sizeof(int)); Inorder to release the memory we will call '"free(p) " How does...
4
by: c language | last post by:
Hi All, I have written a C++ program, it can be compiled (in UNIX) but when I run it, I usually gives the following errors: free(): invalid pointer 0x51d4a0! free(): invalid pointer 0x51d460!...
171
by: Raman | last post by:
Hi All, Here is a small Code, int main(void) { char *p=(char *) malloc(100); strcpy(p,"Test1234567890"); p=p+10; free(p);
76
by: dbansal | last post by:
Hi group, I have a question to ask you all. I have allocated some chunk of memory using ptr=(int*)malloc(). now I am trying to free that memory using free((void*)ptr). My question is does free()...
17
by: anyone.anon | last post by:
Let p=malloc(N) for some N>0. As far as I understand it, free(p+k) for 0<k<N causes undefined behavior, since only a pointer returned by (m| re|c)alloc() can validly be passed to free(). This...
0
by: shrik | last post by:
I have following error : Total giant files in replay configuration file are : File name : /new_file/prob1.rec Given file /new_file/prob1.rec is successfully verified. Splitting for giant file...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.