diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c
index 324a39e..9d88992 100644
*** a/src/backend/catalog/dependency.c
--- b/src/backend/catalog/dependency.c
*************** pg_describe_object(PG_FUNCTION_ARGS)
*** 2830,2837 ****
   * Base function to list an extension's objects, used in the
   * pg_extension_objects SRF.
   *
!  * Be careful to free the locks as soon as possible, by calling the helper
!  * function releaseDependentObjects
   */
  ObjectAddresses *
  listDependentObjects(ObjectAddress *object)
--- 2830,2837 ----
   * Base function to list an extension's objects, used in the
   * pg_extension_objects SRF.
   *
!  * Caller is responsible for freeing the resulting list with
!  * free_object_addresses.
   */
  ObjectAddresses *
  listDependentObjects(ObjectAddress *object)
*************** listDependentObjects(ObjectAddress *obje
*** 2846,2852 ****
  	depRel = heap_open(DependRelationId, RowExclusiveLock);
  
  	/*
! 	 * Construct a list of objects to delete (ie, the given object plus
  	 * everything directly or indirectly dependent on it).
  	 */
  	targetObjects = new_object_addresses();
--- 2846,2852 ----
  	depRel = heap_open(DependRelationId, RowExclusiveLock);
  
  	/*
! 	 * Construct a list of dependent objects (ie, the given object plus
  	 * everything directly or indirectly dependent on it).
  	 */
  	targetObjects = new_object_addresses();
*************** listDependentObjects(ObjectAddress *obje
*** 2861,2873 ****
  	heap_close(depRel, RowExclusiveLock);
  	return targetObjects;
  }
- 
- /*
-  * Release the locks
-  */
- void
- freeDependentObjects(ObjectAddresses *targetObjects)
- {
- 	free_object_addresses(targetObjects);
- 	return;
- }
--- 2861,2863 ----
diff --git a/src/backend/catalog/pg_depend.c b/src/backend/catalog/pg_depend.c
index 2db6972..1ed0021 100644
*** a/src/backend/catalog/pg_depend.c
--- b/src/backend/catalog/pg_depend.c
*************** changeDependencyTypeFor(Oid objid,
*** 311,322 ****
--- 311,329 ----
  			/* make a modifiable copy */
  			tup = heap_copytuple(tup);
  			depform = (Form_pg_depend) GETSTRUCT(tup);
+ 
  			depform->deptype = newtype;
+ 
  			simple_heap_update(depRel, &tup->t_self, tup);
+ 			CatalogUpdateIndexes(depRel, tup);
+ 
+ 			heap_freetuple(tup);
  		}
  	}
+ 
  	systable_endscan(scan);
  	heap_close(depRel, RowExclusiveLock);
+ 
  	return count;
  }
  
diff --git a/src/backend/commands/extension.c b/src/backend/commands/extension.c
index 654b2b8..c226031 100644
*** a/src/backend/commands/extension.c
--- b/src/backend/commands/extension.c
*************** pg_extension_flag_dump(PG_FUNCTION_ARGS)
*** 952,958 ****
  	 */
  	if (!create_extension)
  		ereport(ERROR,
! 				(errmsg("This function can only be used from CREATE EXTENSION.")));
  
  	count = changeDependencyTypeFor(objid,
  									ExtensionRelationId,
--- 952,958 ----
  	 */
  	if (!create_extension)
  		ereport(ERROR,
! 				(errmsg("this function can only be used from CREATE EXTENSION")));
  
  	count = changeDependencyTypeFor(objid,
  									ExtensionRelationId,
*************** pg_extension_flag_dump(PG_FUNCTION_ARGS)
*** 961,980 ****
  
  	if (count == 0)
  		ereport(ERROR,
! 				(errmsg("could not find a pg_depend entry for oid %u "
! 						"referring to current extension.", objid)));
  	else if (count > 1)
  		ereport(ERROR,
! 				(errmsg("current extension has more than one "
! 						"dependency with object id %u.", objid)));
  
  	PG_RETURN_BOOL(true);
  }
  
  /*
!  * read (seqscan) the pg_extension catalog and fill in the exts array (that
!  * we allocate --- the caller has to free it). returns the number of items
!  * added into the array.
   */
  static ExtensionList *
  extension_list_installed(bool name_only)
--- 961,982 ----
  
  	if (count == 0)
  		ereport(ERROR,
! 				(errmsg("could not find a pg_depend entry for oid %u referring to current extension",
! 						objid)));
  	else if (count > 1)
  		ereport(ERROR,
! 				(errmsg("current extension has more than one dependency with object id %u",
! 						objid)));
  
  	PG_RETURN_BOOL(true);
  }
  
  /*
!  * read (seqscan) the pg_extension catalog and return it as a list.
!  * Note that properties other than the name of the extensions are only
!  * filled if the caller specifically asks for them.
!  *
!  * Caller is responsible for freeing the resulting struct.
   */
  static ExtensionList *
  extension_list_installed(bool name_only)
*************** extension_list_installed(bool name_only)
*** 986,992 ****
  	Datum       d_version;
  	ExtensionList *elist;
  
! 	elist = (ExtensionList *)palloc(sizeof(ExtensionList));
  
  	elist->numrefs = 0;
  	elist->maxrefs = 8;
--- 988,994 ----
  	Datum       d_version;
  	ExtensionList *elist;
  
! 	elist = (ExtensionList *) palloc(sizeof(ExtensionList));
  
  	elist->numrefs = 0;
  	elist->maxrefs = 8;
*************** extension_list_installed(bool name_only)
*** 996,1038 ****
  	rel = heap_open(ExtensionRelationId, AccessShareLock);
  	scandesc = heap_beginscan(rel, SnapshotNow, 0, NULL);
  
! 	while ((tuple = heap_getnext(scandesc, ForwardScanDirection)) != NULL)
  	{
! 		if (HeapTupleIsValid(tuple))
! 		{
! 			Form_pg_extension e = (Form_pg_extension) GETSTRUCT(tuple);
  
! 			if( elist->numrefs >= elist->numrefs )
! 			{
! 				elist->maxrefs += 12;
! 				elist->exts = (ExtensionControlFile *)
! 					repalloc(elist->exts,
! 							 elist->maxrefs * sizeof(ExtensionControlFile));
! 			}
  
! 			elist->exts[elist->numrefs].name = pstrdup(NameStr(e->extname));
  
! 			if (!name_only)
! 			{
! 				elist->exts[elist->numrefs].relocatable = e->relocatable;
  
! 				d_version = heap_getattr(tuple,
! 										 Anum_pg_extension_extversion,
! 										 rel->rd_att,
! 										 &visnull);
  
! 				if (visnull)
! 					elist->exts[elist->numrefs].version = NULL;
! 				else
! 					elist->exts[elist->numrefs].version =
! 						pstrdup(TextDatumGetCString(d_version));
  
! 				elist->exts[elist->numrefs].comment =
! 					GetComment(HeapTupleGetOid(tuple), tuple->t_tableOid, 0);
! 			}
! 			elist->numrefs++;
  		}
  	}
  	heap_endscan(scandesc);
  	heap_close(rel, AccessShareLock);
  
--- 998,1038 ----
  	rel = heap_open(ExtensionRelationId, AccessShareLock);
  	scandesc = heap_beginscan(rel, SnapshotNow, 0, NULL);
  
! 	while (HeapTupleIsValid(tuple = heap_getnext(scandesc, ForwardScanDirection)))
  	{
! 		Form_pg_extension e = (Form_pg_extension) GETSTRUCT(tuple);
  
! 		if (elist->numrefs >= elist->maxrefs)
! 		{
! 			elist->maxrefs *= 2;
! 			elist->exts = (ExtensionControlFile *)
! 				repalloc(elist->exts,
! 						 elist->maxrefs * sizeof(ExtensionControlFile));
! 		}
  
! 		elist->exts[elist->numrefs].name = pstrdup(NameStr(e->extname));
  
! 		if (!name_only)
! 		{
! 			elist->exts[elist->numrefs].relocatable = e->relocatable;
  
! 			d_version = heap_getattr(tuple,
! 									 Anum_pg_extension_extversion,
! 									 rel->rd_att,
! 									 &visnull);
  
! 			if (visnull)
! 				elist->exts[elist->numrefs].version = NULL;
! 			else
! 				elist->exts[elist->numrefs].version =
! 					pstrdup(TextDatumGetCString(d_version));
  
! 			elist->exts[elist->numrefs].comment =
! 				GetComment(HeapTupleGetOid(tuple), tuple->t_tableOid, 0);
  		}
+ 		elist->numrefs++;
  	}
+ 
  	heap_endscan(scandesc);
  	heap_close(rel, AccessShareLock);
  
*************** pg_extension_objects(PG_FUNCTION_ARGS)
*** 1228,1234 ****
  		tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
  		SRF_RETURN_NEXT(funcctx, HeapTupleGetDatum(tuple));
  	}
! 	freeDependentObjects(fctx->targetObjects);
  	SRF_RETURN_DONE(funcctx);
  }
  
--- 1228,1234 ----
  		tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
  		SRF_RETURN_NEXT(funcctx, HeapTupleGetDatum(tuple));
  	}
! 	free_object_addresses(fctx->targetObjects);
  	SRF_RETURN_DONE(funcctx);
  }
  
*************** AlterExtensionNamespace_oid(Oid extensio
*** 1310,1313 ****
--- 1310,1315 ----
  	/* update dependencies to point to the new schema */
  	changeDependencyFor(ExtensionRelationId, extensionOid,
  						NamespaceRelationId, oldNspOid, nspOid);
+ 
+ 	free_object_addresses(targetObjects);
  }
diff --git a/src/include/catalog/dependency.h b/src/include/catalog/dependency.h
index d32efa8..c2e0a43 100644
*** a/src/include/catalog/dependency.h
--- b/src/include/catalog/dependency.h
*************** extern void record_object_address_depend
*** 208,214 ****
  extern void free_object_addresses(ObjectAddresses *addrs);
  
  extern ObjectAddresses *listDependentObjects(ObjectAddress *object);
- extern void freeDependentObjects(ObjectAddresses *targetObjects);
  
  /* in pg_depend.c */
  
--- 208,213 ----
diff --git a/src/include/commands/extension.h b/src/include/commands/extension.h
index 2d9bd9b..91a6a83 100644
*** a/src/include/commands/extension.h
--- b/src/include/commands/extension.h
*************** typedef struct ExtensionList
*** 51,57 ****
  } ExtensionList;
  
  
! typedef struct
  {
  	ObjectAddresses *targetObjects;
  	int i;
--- 51,57 ----
  } ExtensionList;
  
  
! typedef struct extension_objects_fctx
  {
  	ObjectAddresses *targetObjects;
  	int i;
diff --git a/src/include/utils/genfile.h b/src/include/utils/genfile.h
index aaa415d..e343a9d 100644
*** a/src/include/utils/genfile.h
--- b/src/include/utils/genfile.h
***************
*** 12,23 ****
  #define GENFILE_H
  
  #include <dirent.h>
- #include "utils/array.h"
  
  /*
!  * We need that in extension.c in the SRF that lists available extensions.
   */
! typedef struct
  {
  	char	   *location;
  	DIR		   *dirdesc;
--- 12,22 ----
  #define GENFILE_H
  
  #include <dirent.h>
  
  /*
!  * We need this in extension.c in the SRF that lists available extensions.
   */
! typedef struct directory_fctx
  {
  	char	   *location;
  	DIR		   *dirdesc;
