I'm using dmalloc 4.8.2 on Mandrake 8.1 to debug a small C library I'm
writing (the library fakes large files on systems that don't have them). In
addition to the library itself, I'm writing a Python binding. My C test
program runs without complaint, but the Python test script generates a
"pointer is not pointing to heap data space" error, which I think is
spurious. This error occurs in the close function, where all the little
fiddly bits get freed. At the top of the close function The struct looks
like this in gdb:
$36 = {
mode = 0x821da48 "w",
pad1 = 0x0,
pad2 = 0x0,
path = 0x8222b98 "foo1",
pad3 = 0x0,
pad4 = 0x0,
position = 4020,
length = 4020,
basedir = 0x8248348,
current = 0x8173468,
nchunks = 2,
current_chunk = 1,
chunks = 0x8251108
}
(Note the four pad fields. They are just fences around the path field.)
The close function looks like
static int
_alf_close (ALF *stream)
{
int i,n;
n = fclose(stream->current);
stream->current = NULL;
for (i=0;i<stream->nchunks;i++)
free(stream->chunks[i].path);
free(stream->chunks);
stream->chunks = NULL;
n = n || closedir(stream->basedir);
stream->basedir = NULL;
free(stream->path);
stream->path = NULL;
free(stream->mode);
stream->mode = NULL;
return n;
}
When an attempt is made to free stream->path, dmalloc emits the non-heap
pointer error. However, it seems to me the pointer is within range. (It
was allocated by a call to strdup.) The basedir, current, and chunks fields
have all successfully been freed and set to NULL by the time the path field
itself is freed:
$37 = {
mode = 0x821da48 "w",
pad1 = 0x0,
pad2 = 0x0,
path = 0x8222b98 "foo1",
pad3 = 0x0,
pad4 = 0x0,
position = 4020,
length = 4020,
basedir = 0x0,
current = 0x0,
nchunks = 2,
current_chunk = 1,
chunks = 0x0
}
I'm running dmalloc with the following settings:
log-stats, log-non-free, log-trans, log-admin, check-fence, check-funcs,
check-heap, check-lists, realloc-copy, free-blank, error-abort,
alloc-blank
Python itself was not built with dmalloc, but the C code that went into
making the library available to Python was (the library itself and the
wrapper code that exposes the library to Python).
Any idea what might be going on?
Thx,
--
Skip Montanaro (
skip@... -
http://www.mojam.com/)