On Wed, Jul 08, 2009 at 02:12:09AM -0000, Jay Pipes wrote:
> >>>> + if (buffer == NULL)
> >>>> + {
> >>>> + /*
> >>>> + * First time around...just malloc the length. This block gets
> >>>> rid
> >>>> + * of a GCC warning about uninitialized temp_buffer.
> >>>> + */
> >>>> + temp_buffer= (char *) malloc((size_t) length);
> >>>> + }
> >>>> + /* No need to allocate if we have a buffer big enough... */
> >>>> + else if (length > previous_length)
> >>>> + {
> >>>> + temp_buffer= (char *) realloc(buffer, (size_t) length);
> >>>> + }
> >>> Since doing own memory allocation, and thwarting some valgrind
> >>> effectiveness, if we have the valgrind headers, after this there should
> >>> be a use of the VALGRIND_MAKE_MEM_UNDEFINED() macro to tell valgrind
> >>> that the bit of memory we've malloc()'d should now be considered
> >>> garbage, and warn us if we access it. (it's in valgrind/memcheck.h)
> >> The code above works fine. Not sure why there is a need for a change.
> >> The above code meets the valgrind requirements from krow (no valgrind
> >> errors or warnings produced).
> >
> > The above could hide errors as if:
> > 'AAAAAAAAAAAAAAAAAAAAAAAAAA'
> > next message size less than previous, don't realloc:
> > 'BBBBB'
> > but then access buffer[15], you won't get a valgrind warning as in the
> > previous message you will have set the memory as defined.
> >
> > The VALGRIND_MAKE_MEM_UNDEFINED() macro tells valgrind to treat the
> > block of memory as if you've just allocated it, and in the above case,
> > if called around the 'so don't realloc' logic, you'd get a valgrind
> > warning when you access buffer[15].
>
> I used to have a memset() directly after these calls. Brian had me
> remove it. I wish the two of you would figure out how you want to
> handle these situations, as I've now changed the above code three or
> four times because each of you says different things...
The memset() will always be there, but for builds we don't want to run
valgrind on (or indeed, even if it is compiled in, it's only a few instr
doing a no-op) the valgrind macros go to nothing.
But yeah, we should have some sort of policy here.
--
Stewart Smith
_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to : [email protected]
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help : https://help.launchpad.net/ListHelp