postgresql/src/backend/utils
Tomas Vondra f2369bc610 Use Size instead of int64 to track allocated memory
Commit 5dd7fc1519 added block-level memory accounting, but used int64 variable to
track the amount of allocated memory. That is incorrect, because we have Size for
exactly these purposes, but it was mostly harmless until c477f3e449 which changed
how we handle with repalloc() when downsizing the chunk. Previously we've ignored
these cases and just kept using the original chunk, but now we need to update the
accounting, and the code was doing this:

    context->mem_allocated += blksize - oldblksize;

Both blksize and oldblksize are Size (so unsigned) which means the subtraction
underflows, producing a very high positive value. On 64-bit platforms (where Size
has the same size as mem_alllocated) this happens to work because the result wraps
to the right value, but on (some) 32-bit platforms this fails.

This fixes two things - it changes mem_allocated (and related variables) to Size,
and it splits the update to two separate steps, to prevent any underflows.

Discussion: https://www.postgresql.org/message-id/15151.1570163761%40sss.pgh.pa.us
2019-10-04 16:10:56 +02:00
..
adt Fix implicit-fallthrough compiler warning introduced in 6dda292d4d. 2019-09-27 10:29:25 -07:00
cache Fix handling of non-key columns get_index_column_opclass() 2019-09-09 13:50:12 +03:00
error Update copyright for 2019 2019-01-02 12:44:25 -05:00
fmgr Split tuptoaster.c into three separate files. 2019-09-05 13:15:10 -04:00
hash Fix incidental warnings from cpluspluscheck. 2019-08-18 19:01:40 -04:00
init Revert hooks for session start and end, take two 2019-10-02 09:55:27 +09:00
mb Avoid unnecessary out-of-memory errors during encoding conversion. 2019-10-03 17:34:25 -04:00
misc Message style fixes 2019-09-23 13:38:39 +02:00
mmgr Use Size instead of int64 to track allocated memory 2019-10-04 16:10:56 +02:00
resowner Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
sort Make tuplesort_set_bound() assertions more comprehensible, hopefully. 2019-09-13 16:57:07 -04:00
time Fix inconsistencies and typos in the tree, take 9 2019-08-05 12:14:58 +09:00
.gitignore Rearrange makefile rules for running Gen_fmgrtab.pl. 2018-05-03 17:54:18 -04:00
errcodes.txt Implement jsonpath .datetime() method 2019-09-25 22:51:51 +03:00
Gen_dummy_probes.pl Fix many typos and inconsistencies 2019-07-01 10:00:23 +09:00
Gen_dummy_probes.sed Update copyright for 2019 2019-01-02 12:44:25 -05:00
Gen_fmgrtab.pl Fix more typos and inconsistencies in the tree 2019-06-17 16:13:16 +09:00
generate-errcodes.pl Update copyright for 2019 2019-01-02 12:44:25 -05:00
Makefile Use Getopt::Long for catalog scripts 2019-02-12 12:22:08 -03:00
probes.d Update copyright for 2019 2019-01-02 12:44:25 -05:00