diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 77bf8acd9fb37e28ad88af29048fc8b91ce73f57..077b37eb43dbedce1d2ecf0bec390f57880685db 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -11580,6 +11580,7 @@ dumpAccessMethod(Archive *fout, AccessMethodInfo *aminfo)
 		default:
 			write_msg(NULL, "WARNING: invalid type %c of access method %s\n",
 					  aminfo->amtype, qamname);
+			pg_free(qamname);
 			destroyPQExpBuffer(q);
 			destroyPQExpBuffer(delq);
 			destroyPQExpBuffer(labelq);
@@ -11609,7 +11610,7 @@ dumpAccessMethod(Archive *fout, AccessMethodInfo *aminfo)
 				NULL, "",
 				aminfo->dobj.catId, 0, aminfo->dobj.dumpId);
 
-	free(qamname);
+	pg_free(qamname);
 
 	destroyPQExpBuffer(q);
 	destroyPQExpBuffer(delq);