I thought I was finally clear of bugs when Valgrind printed a huge list of errors about a file I open and later free. They all come from "(below main)"; here are the first and last:
Code:
==32022== Invalid read of size 4
==32022== at 0x40B11AD: (within /lib/tls/i686/cmov/libc-2.8.90.so)
==32022== by 0x40B1E7F: (within /lib/tls/i686/cmov/libc-2.8.90.so)
==32022== by 0x4072DE9: exit (in /lib/tls/i686/cmov/libc-2.8.90.so)
==32022== by 0x405A68C: (below main) (in /lib/tls/i686/cmov/libc-2.8.90.so)
==32022== Address 0x41a49f8 is 104 bytes inside a block of size 352 free'd
==32022== at 0x4024E5A: free (vg_replace_malloc.c:323)
==32022== by 0x804A3F6: outline_free (outline.c:324)
==32022== by 0x8049369: main (main.c:234)
==32022== Invalid read of size 4
==32022== at 0x416BD4A: (within /lib/tls/i686/cmov/libc-2.8.90.so)
==32022== by 0x416BDD9: (within /lib/tls/i686/cmov/libc-2.8.90.so)
==32022== by 0x401F422: _vgnU_freeres (vg_preloaded.c:60)
==32022== by 0x40E12B3: _Exit (in /lib/tls/i686/cmov/libc-2.8.90.so)
==32022== by 0x405A68C: (below main) (in /lib/tls/i686/cmov/libc-2.8.90.so)
==32022== Address 0x41a49ec is 92 bytes inside a block of size 352 free'd
==32022== at 0x4024E5A: free (vg_replace_malloc.c:323)
==32022== by 0x804A3F6: outline_free (outline.c:324)
==32022== by 0x8049369: main (main.c:234)
And here are the involved functions:
Code:
struct outline *outline_load(char *title){
struct outline *this;
if(title == (char *)NULL || strcmp(title, "") == 0)
return (struct outline *)NULL;
this = outline_create(title);
char *path = malloc(strlen(outline_home) + 7 + strlen(title) + 1),
*pattern = "%s" SLASH "files" SLASH "%s";
CHECK(path);
sprintf(path, pattern, outline_home, title);
this->old = file_exists(path);
if(this->old == 0)
COMMAND("echo >", path);
this->file = fopen(path, "w+");
...
free(path);
return this;
}
void outline_free(void *o){
struct outline *this = (struct outline *)o;
outline_item_free(this->root);
free(this->file);
free(this);
}
I don't recall doing anything significant just before the errors appeared... Any ideas?
Thanks!
Chris