Re: Possible false valgrind error reports - Mailing list pgsql-hackers

From Karina Litskevich
Subject Re: Possible false valgrind error reports
Date
Msg-id CACiT8ia=83qScbh4qifi8y6gxygDoTsyppuCY2JhjZ4hnQhp_w@mail.gmail.com
Whole thread Raw
In response to Re: Possible false valgrind error reports  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Possible false valgrind error reports
List pgsql-hackers
Thank you, I moved comment changes to 0001 and rewrote the fix through Min().

> The first hunk in 0001 doesn't seem quite right yet:
>
>           * old allocation.
>           */
>  #ifdef USE_VALGRIND
> -        if (oldsize > chunk->requested_size)
> +        if (size > chunk->requested_size && oldsize > chunk->requested_size)
>              VALGRIND_MAKE_MEM_UNDEFINED((char *) pointer + chunk->requested_size,
>                                          oldsize - chunk->requested_size);
>  #endif
>
> If size < oldsize, aren't we still doing the wrong thing?  Seems like
> maybe it has to be like

If size > chunk->requested_size than chksize >= oldsize and so we can mark this
memory without worries. Region from size to chksize will be marked NOACCESS
later anyway:

/* Ensure any padding bytes are marked NOACCESS. */
VALGRIND_MAKE_MEM_NOACCESS((char *) pointer + size, chksize - size);

I agree that it's not obvious, so I changed the first hunk like this:

- if (oldsize > chunk->requested_size)
+ if (Min(size, oldsize) > chunk->requested_size)
  VALGRIND_MAKE_MEM_UNDEFINED((char *) pointer + chunk->requested_size,
- oldsize - chunk->requested_size);
+ Min(size, oldsize) - chunk->requested_size);

Any ideas on how to make this place easier to understand and comment above it
concise and clear are welcome.

There is another thing about this version. New line
+ Min(size, oldsize) - chunk->requested_size);
is longer than 80 symbols and I don't know what's the best way to avoid this
without making it look weird.

I also noticed that if RANDOMIZE_ALLOCATED_MEMORY is defined then
randomize_mem()
have already marked this memory UNDEFINED. So we only "may need to adjust
trailing bytes" if RANDOMIZE_ALLOCATED_MEMORY isn't defined. I reflected it in
v2 of 0001 too.

Attachment

pgsql-hackers by date:

Previous
From: Dmitry Dolgov
Date:
Subject: Re: pg_stat_statements and "IN" conditions
Next
From: "Jonathan S. Katz"
Date:
Subject: Re: The output sql generated by pg_dump for a create function refers to a modified table name