Avoid consuming unreasonable amounts of memory when GRANT has many

grantees.
This commit is contained in:
Tom Lane 2003-09-04 15:53:04 +00:00
parent fe055e9280
commit ca43f71ca5
1 changed files with 14 additions and 12 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.87 2003/08/04 02:39:58 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.88 2003/09/04 15:53:04 tgl Exp $
*
* NOTES
* See acl.h.
@ -72,6 +72,8 @@ dumpacl(Acl *acl)
* If is_grant is true, adds the given privileges for the list of
* grantees to the existing old_acl. If is_grant is false, the
* privileges for the given grantees are removed from old_acl.
*
* NB: the original old_acl is pfree'd.
*/
static Acl *
merge_acl_with_grant(Acl *old_acl, bool is_grant,
@ -94,6 +96,7 @@ merge_acl_with_grant(Acl *old_acl, bool is_grant,
PrivGrantee *grantee = (PrivGrantee *) lfirst(j);
AclItem aclitem;
uint32 idtype;
Acl *newer_acl;
if (grantee->username)
{
@ -133,7 +136,11 @@ merge_acl_with_grant(Acl *old_acl, bool is_grant,
(grant_option || !is_grant) ? privileges : ACL_NO_RIGHTS,
idtype);
new_acl = aclinsert3(new_acl, &aclitem, modechg, behavior);
newer_acl = aclinsert3(new_acl, &aclitem, modechg, behavior);
/* avoid memory leak when there are many grantees */
pfree(new_acl);
new_acl = newer_acl;
#ifdef ACLDEBUG
dumpacl(new_acl);
@ -269,7 +276,6 @@ ExecuteGrantStmt_Relation(GrantStmt *stmt)
/* keep the catalog indexes up to date */
CatalogUpdateIndexes(relation, newtuple);
pfree(old_acl);
pfree(new_acl);
heap_close(relation, RowExclusiveLock);
@ -366,7 +372,6 @@ ExecuteGrantStmt_Database(GrantStmt *stmt)
/* keep the catalog indexes up to date */
CatalogUpdateIndexes(relation, newtuple);
pfree(old_acl);
pfree(new_acl);
heap_endscan(scan);
@ -465,7 +470,6 @@ ExecuteGrantStmt_Function(GrantStmt *stmt)
/* keep the catalog indexes up to date */
CatalogUpdateIndexes(relation, newtuple);
pfree(old_acl);
pfree(new_acl);
heap_close(relation, RowExclusiveLock);
@ -565,7 +569,6 @@ ExecuteGrantStmt_Language(GrantStmt *stmt)
/* keep the catalog indexes up to date */
CatalogUpdateIndexes(relation, newtuple);
pfree(old_acl);
pfree(new_acl);
heap_close(relation, RowExclusiveLock);
@ -662,7 +665,6 @@ ExecuteGrantStmt_Namespace(GrantStmt *stmt)
/* keep the catalog indexes up to date */
CatalogUpdateIndexes(relation, newtuple);
pfree(old_acl);
pfree(new_acl);
heap_close(relation, RowExclusiveLock);