Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ac673a1

Browse files
committed
Avoid useless allocations for information of dumpable objects in pg_dump/
If there are no objects of a certain type, there is no need to do an allocation for a set of DumpableObject items. The previous coding did an allocation of 1 byte instead as per the fallback of pg_malloc() in the event of an allocation size of zero. This assigns NULL instead for a set of dumpable objects. A similar rule already applied to findObjectByOid(), so this makes the code more defensive as we would just fail with a pointer dereference instead of attempting to use some incorrect data if a non-existing, positive, OID is given by a caller of this function. Author: Daniel Gustafsson Reviewed-by: Julien Rouhaud, Ranier Vilela Discussion: https://postgr.es/m/26C43E58-BDD0-4F1A-97CC-4A07B52E32C5@yesql.se
1 parent 19f5a37 commit ac673a1

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/bin/pg_dump/common.c

+3
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,9 @@ buildIndexArray(void *objArray, int numObjs, Size objSize)
719719
DumpableObject **ptrs;
720720
int i;
721721

722+
if (numObjs <= 0)
723+
return NULL;
724+
722725
ptrs = (DumpableObject **) pg_malloc(numObjs * sizeof(DumpableObject *));
723726
for (i = 0; i < numObjs; i++)
724727
ptrs[i] = (DumpableObject *) ((char *) objArray + i * objSize);

0 commit comments

Comments
 (0)