Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

failing at linked list / memory

Name: Anonymous 2010-04-29 9:36

http://codepad.org/QN4Noquq

Somebody please tell me what I am doing wrong here.  The problem is line 174, which is in list_delete():

free(temp->next);

In Windows the program just stops working correctly (or in this case just terminates since my testcase is very short). In GDB, it gives me the following output when I run the program:
warning: HEAP[list.exe]:
warning: Heap block at 00391060 modified at 0039106C past requested size of 4


I know it's that line because it's in the backtrace and I've stepped through that code many times.
I can't figure out what's wrong with freeing temp->next there.  If I print temp->next->data->name just before that line it gives me the expected string, so the memory has to be ok and I'm trying to delete the free the right struct.  I just don't understand what the problem is here.

Name: Anonymous 2010-04-29 9:45

>>1
That's heap corruption. That warning isn't generated by gdb, but by NTDLL due to loader snap option being enabled(which you either enabled it yourself, or gdb did it for you). Common reasons for heap corruption include freeing something that was already freed or writing way past the bounds(or before) of your buffer(overflow).

Name: Anonymous 2010-04-29 9:56

>>1
How does your foot feel?

Name: >>2 2010-04-29 10:39

I know it's that line because it's in the backtrace and I've stepped through that code many times.
It's just that the corruption is detected when you're trying to free that block. That doesn't mean the free is causing the corruption. If I wasn't lazy I'd try to debug your code.

Name: Anonymous 2010-04-29 13:06

nodeNew = malloc( sizeof(node_t*) );
Spotted this while scrolling over your code. Good job allocating four bytes for a struct that needs at least eight bytes of memory.

Name: Anonymous 2010-04-29 14:41

>>5
But it works on x86_64!

Name: Anonymous 2010-04-29 15:25

>>5
actual storage size / alignment is not standardized by C, so that is only the case on some systems

Name: Anonymous 2010-04-29 15:37

>>6
On x86_64, you'd need 16bytes(sizeof(pointer*)*2)

Name: Anonymous 2010-04-29 16:04

>>7
s/some/the vast majority of/x;

Name: Anonymous 2010-04-29 16:53

>>9
s/s\/some\/the\\ vast\\ majority\\ of\/x;/;

Name: Anonymous 2010-04-29 17:30

>>8
But if you compiled the struct on 32-bit and the allocation on 64-bit, then everything would work!

Name: Anonymous 2010-04-29 20:36

>>11
As punishment for this joke, you must write me a BBCode optimizer.

Name: Anonymous 2010-04-29 23:02

>>10
s/s\/some\/the\\ vast\\ majority\\ of\/x;/;
This is what PHP programmers actually think.

Name: Anonymous 2010-04-30 1:17

>>5
oh fuck, thanks.  I don't know how I managed to do that :|  Stupid mistake.

Name: Anonymous 2010-04-30 18:38

>>5 They almost always are.

I (well, there where 2 of us, which makes this worse) spent 2 hours (very very late hours) trying to figure out why a function I wrote wasn't modifying an array. (I was printing parts of the array to debug).

Turns out I called the print function before calling the array modifier.  Yes, that took 2 hours to debug

If I had a razor-tipped whipping lash, I would have used it on myself.

Name: Anonymous 2010-05-01 17:12

>>15
gotta love programming

Name: Anonymous 2010-05-02 8:35

>>16
You can't make me, jerkface.

Name: Anonymous 2010-12-17 1:35

Are you GAY?
Are you a NIGGER?
Are you a GAY NIGGER?

If you answered "Yes" to all of the above questions, then GNAA (GAY NIGGER ASSOCIATION OF AMERICA) might be exactly what you've been looking for!

Name: Anonymous 2011-02-04 18:48


Don't change these.
Name: Email:
Entire Thread Thread List