diff --git a/contrib/pg_upgrade/tablespace.c b/contrib/pg_upgrade/tablespace.c
index 302eb0d..99a97e4 100644
--- a/contrib/pg_upgrade/tablespace.c
+++ b/contrib/pg_upgrade/tablespace.c
@@ -49,7 +49,10 @@ get_tablespace_paths(migratorContext *ctx)
 							"		spcname != 'pg_global'");
 
 	ctx->num_tablespaces = ntups = PQntuples(res);
-	ctx->tablespaces = (char **) pg_malloc(ctx, ntups * sizeof(char *));
+	if( ntups > 0 ) 	
+		ctx->tablespaces = (char **) pg_malloc(ctx, ntups * sizeof(char *));
+	else
+		ctx->tablespaces=0;
 
 	i_spclocation = PQfnumber(res, "spclocation");
 
-- 
1.6.3.3

