diff --git a/expected/pgaudit.out b/expected/pgaudit.out
index 17e8de1..eafe356 100644
--- a/expected/pgaudit.out
+++ b/expected/pgaudit.out
@@ -2728,6 +2728,56 @@ NOTICE:  AUDIT: SESSION,14,1,READ,SELECT,TABLE,public.graph_vertex,"SELECT name
 
 DROP PROPERTY GRAPH graph_test;
 DROP TABLE graph_vertex;
+--
+-- Test that a role substatement (GRANT) collected as the last command of a DDL
+-- statement does not cause the statement to be logged a second time by the
+-- ProcessUtility hook, reading the object name/type after their memory context
+-- has been freed, when only DDL is being logged.
+SET pgaudit.log = 'none';
+CREATE EXTENSION pgaudit;
+SET pgaudit.log_client = on;
+SET pgaudit.log_level = 'notice';
+SET pgaudit.log_relation = off;
+SET pgaudit.log = 'ddl';
+CREATE TABLE schema_grant_tbl (id int);
+NOTICE:  AUDIT: SESSION,15,1,DDL,CREATE TABLE,TABLE,public.schema_grant_tbl,CREATE TABLE schema_grant_tbl (id int),<not logged>
+CREATE ROLE regress_schema_grant;
+CREATE SCHEMA schema_grant
+	GRANT SELECT
+	   ON public.schema_grant_tbl
+	   TO regress_schema_grant;
+NOTICE:  AUDIT: SESSION,16,1,DDL,CREATE SCHEMA,SCHEMA,schema_grant,"CREATE SCHEMA schema_grant
+	GRANT SELECT
+	   ON public.schema_grant_tbl
+	   TO regress_schema_grant",<not logged>
+-- The same scenario written with the CREATE SCHEMA ... AUTHORIZATION form.  Its
+-- schema elements execute as the target role, so create the table as an element
+-- (owned by that role) and grant on it; the trailing GRANT substatement
+-- exercises the same path.
+CREATE ROLE regress_schema_auth;
+CREATE SCHEMA AUTHORIZATION regress_schema_auth
+	CREATE TABLE schema_auth_tbl (id int)
+	GRANT SELECT
+	   ON schema_auth_tbl
+	   TO PUBLIC;
+NOTICE:  AUDIT: SESSION,17,1,DDL,CREATE SCHEMA,SCHEMA,regress_schema_auth,"CREATE SCHEMA AUTHORIZATION regress_schema_auth
+	CREATE TABLE schema_auth_tbl (id int)
+	GRANT SELECT
+	   ON schema_auth_tbl
+	   TO PUBLIC",<not logged>
+NOTICE:  AUDIT: SESSION,17,1,DDL,CREATE TABLE,TABLE,regress_schema_auth.schema_auth_tbl,"CREATE SCHEMA AUTHORIZATION regress_schema_auth
+	CREATE TABLE schema_auth_tbl (id int)
+	GRANT SELECT
+	   ON schema_auth_tbl
+	   TO PUBLIC",<not logged>
+SET pgaudit.log = 'none';
+DROP SCHEMA schema_grant;
+DROP SCHEMA regress_schema_auth CASCADE;
+NOTICE:  drop cascades to table regress_schema_auth.schema_auth_tbl
+DROP TABLE schema_grant_tbl;
+DROP ROLE regress_schema_grant;
+DROP ROLE regress_schema_auth;
+DROP EXTENSION pgaudit;
 -- Cleanup
 -- Set client_min_messages up to warning to avoid noise
 SET client_min_messages = 'warning';
diff --git a/pgaudit.c b/pgaudit.c
index 0086883..c5cca00 100644
--- a/pgaudit.c
+++ b/pgaudit.c
@@ -1879,6 +1879,12 @@ pgaudit_ddl_command_end(PG_FUNCTION_ARGS)
         }
         else
             log_audit_event(auditEventStack);
+
+        /*
+        * Mark the audit event as logged so it won't be logged again with fields
+        * that have been freed.
+        */
+        auditEventStack->auditEvent.logged = true;
     }
 
     /* Complete the query */
@@ -1962,6 +1968,12 @@ pgaudit_sql_drop(PG_FUNCTION_ARGS)
 
         auditEventStack->auditEvent.logged = false;
         log_audit_event(auditEventStack);
+
+        /*
+        * Mark the audit event as logged so it won't be logged again with fields
+        * that have been freed.
+        */
+        auditEventStack->auditEvent.logged = true;
     }
 
     /* Complete the query */
diff --git a/sql/pgaudit.sql b/sql/pgaudit.sql
index 9dfc571..a4f2169 100644
--- a/sql/pgaudit.sql
+++ b/sql/pgaudit.sql
@@ -1750,6 +1750,47 @@ SELECT name
 DROP PROPERTY GRAPH graph_test;
 DROP TABLE graph_vertex;
 
+--
+-- Test that a role substatement (GRANT) collected as the last command of a DDL
+-- statement does not cause the statement to be logged a second time by the
+-- ProcessUtility hook, reading the object name/type after their memory context
+-- has been freed, when only DDL is being logged.
+SET pgaudit.log = 'none';
+CREATE EXTENSION pgaudit;
+
+SET pgaudit.log_client = on;
+SET pgaudit.log_level = 'notice';
+SET pgaudit.log_relation = off;
+SET pgaudit.log = 'ddl';
+
+CREATE TABLE schema_grant_tbl (id int);
+CREATE ROLE regress_schema_grant;
+
+CREATE SCHEMA schema_grant
+	GRANT SELECT
+	   ON public.schema_grant_tbl
+	   TO regress_schema_grant;
+
+-- The same scenario written with the CREATE SCHEMA ... AUTHORIZATION form.  Its
+-- schema elements execute as the target role, so create the table as an element
+-- (owned by that role) and grant on it; the trailing GRANT substatement
+-- exercises the same path.
+CREATE ROLE regress_schema_auth;
+
+CREATE SCHEMA AUTHORIZATION regress_schema_auth
+	CREATE TABLE schema_auth_tbl (id int)
+	GRANT SELECT
+	   ON schema_auth_tbl
+	   TO PUBLIC;
+
+SET pgaudit.log = 'none';
+DROP SCHEMA schema_grant;
+DROP SCHEMA regress_schema_auth CASCADE;
+DROP TABLE schema_grant_tbl;
+DROP ROLE regress_schema_grant;
+DROP ROLE regress_schema_auth;
+DROP EXTENSION pgaudit;
+
 -- Cleanup
 -- Set client_min_messages up to warning to avoid noise
 SET client_min_messages = 'warning';
