*
*
* 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.
* 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,
foreach(j, grantees)
{
PrivGrantee *grantee = (PrivGrantee *) lfirst(j);
- AclItem aclitem;
+ AclItem aclitem;
uint32 idtype;
+ Acl *newer_acl;
if (grantee->username)
{
- aclitem. ai_grantee = get_usesysid(grantee->username);
+ aclitem.ai_grantee = get_usesysid(grantee->username);
idtype = ACL_IDTYPE_UID;
}
else if (grantee->groupname)
{
- aclitem. ai_grantee = get_grosysid(grantee->groupname);
+ aclitem.ai_grantee = get_grosysid(grantee->groupname);
idtype = ACL_IDTYPE_GID;
}
else
{
- aclitem. ai_grantee = ACL_ID_WORLD;
+ aclitem.ai_grantee = ACL_ID_WORLD;
idtype = ACL_IDTYPE_WORLD;
}
(errcode(ERRCODE_INVALID_GRANT_OPERATION),
errmsg("grant options can only be granted to individual users")));
- aclitem. ai_grantor = GetUserId();
+ aclitem.ai_grantor = GetUserId();
ACLITEM_SET_PRIVS_IDTYPE(aclitem,
(is_grant || !grant_option) ? privileges : ACL_NO_RIGHTS,
(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);
/* keep the catalog indexes up to date */
CatalogUpdateIndexes(relation, newtuple);
- pfree(old_acl);
pfree(new_acl);
heap_close(relation, RowExclusiveLock);
/* keep the catalog indexes up to date */
CatalogUpdateIndexes(relation, newtuple);
- pfree(old_acl);
pfree(new_acl);
heap_endscan(scan);
/* keep the catalog indexes up to date */
CatalogUpdateIndexes(relation, newtuple);
- pfree(old_acl);
pfree(new_acl);
heap_close(relation, RowExclusiveLock);
/* keep the catalog indexes up to date */
CatalogUpdateIndexes(relation, newtuple);
- pfree(old_acl);
pfree(new_acl);
heap_close(relation, RowExclusiveLock);
/* keep the catalog indexes up to date */
CatalogUpdateIndexes(relation, newtuple);
- pfree(old_acl);
pfree(new_acl);
heap_close(relation, RowExclusiveLock);