basepi / libgit2

The Library
http://libgit2.github.com
Other
0 stars 0 forks source link

We free a pointer that wasn't malloc'd #15

Closed hausdorf closed 13 years ago

hausdorf commented 13 years ago

PROBLEM: A call to git_diff_no_index() will allocate the contents of file at params filepath1 and filepath2 to a char *buffer1 and char *buffer2. Running this method will produce the following error: a.out(5679) malloc: *** error for object 0x100800000: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug [1] 5679 abort ./a.out What's going on here is that we're free'ing here without actually having malloc'd the memory to begin with.

NOTES:

I would've just fixed this, but I wasn't sure if that would conflict with resolution of #14.

vimalloc commented 13 years ago

It should be getting malloc'd through load file, hence why we pass it a double pointer.

I can take a look at it in a bit.

hausdorf commented 13 years ago

@kyeana, take your time. Filed a bug report so that we could get around to it when we want to.

You can see what the bug looks like for us here

vimalloc commented 13 years ago

Awesome sauce

hausdorf commented 13 years ago

What's really happening here is that the call to load_file() in this line fails at some point. Since it never gets malloc'd, freeing it causes an error.

vimalloc commented 13 years ago

Problem was char *buffer1; initializes buffer1 to garbage, not to null, thus the if(buffer1) returns true and we try to free stuff we never malloc'd.

Fix in my branch.

basepi commented 13 years ago

Did you push that to the server, @kyeana? The comments in, for example, in git_diff_no_index, there are still comments referencing #15, and yes, I've pulled from master very recently.

basepi commented 13 years ago

OK, I found your fix, you just didn't remove the comments.