[HACKERS] 9.0 beta2 pg_upgrade: malloc 0 bytes patch

2010-06-16 Thread Steve Singer


Running pg_upgrade against an unmodified (the output of initdb) cluster 
on AIX is giving me  pg_alloc: Out of memory errors.


On some non-linux platforms (including AIX) malloc(0) returns 0.

with the attached patch to pg_upgrade I am now able to get pg_upgrade to 
convert an 8.3 database consisting of a single table to 9.0 on an AIX 
server.





--
Steve Singer
Afilias Canada
Data Services Developer
416-673-1142
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


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] 9.0 beta2 pg_upgrade: malloc 0 bytes patch

2010-06-16 Thread Bruce Momjian
Steve Singer wrote:
 
 Running pg_upgrade against an unmodified (the output of initdb) cluster 
 on AIX is giving me  pg_alloc: Out of memory errors.
 
 On some non-linux platforms (including AIX) malloc(0) returns 0.
 
 with the attached patch to pg_upgrade I am now able to get pg_upgrade to 
 convert an 8.3 database consisting of a single table to 9.0 on an AIX 
 server.

Great, thanks for your testing.  I have applied a modified version of
the patch, attached.

-- 
  Bruce Momjian  br...@momjian.ushttp://momjian.us
  EnterpriseDB http://enterprisedb.com

  + None of us is going to be here forever. +
Index: contrib/pg_upgrade/tablespace.c
===
RCS file: /cvsroot/pgsql/contrib/pg_upgrade/tablespace.c,v
retrieving revision 1.1
diff -c -c -r1.1 tablespace.c
*** contrib/pg_upgrade/tablespace.c	12 May 2010 02:19:11 -	1.1
--- contrib/pg_upgrade/tablespace.c	16 Jun 2010 19:37:23 -
***
*** 38,44 
  {
  	PGconn	   *conn = connectToServer(ctx, template1, CLUSTER_OLD);
  	PGresult   *res;
- 	int			ntups;
  	int			tblnum;
  	int			i_spclocation;
  
--- 38,43 
***
*** 48,59 
  			WHERE	spcname != 'pg_default' AND 
  	spcname != 'pg_global');
  
! 	ctx-num_tablespaces = ntups = PQntuples(res);
! 	ctx-tablespaces = (char **) pg_malloc(ctx, ntups * sizeof(char *));
  
  	i_spclocation = PQfnumber(res, spclocation);
  
! 	for (tblnum = 0; tblnum  ntups; tblnum++)
  		ctx-tablespaces[tblnum] = pg_strdup(ctx,
  	 PQgetvalue(res, tblnum, i_spclocation));
  
--- 47,61 
  			WHERE	spcname != 'pg_default' AND 
  	spcname != 'pg_global');
  
! 	if ((ctx-num_tablespaces = PQntuples(res)) != 0)
! 		ctx-tablespaces = (char **) pg_malloc(ctx,
! 	ctx-num_tablespaces * sizeof(char *));
! 	else
! 		ctx-tablespaces = NULL;
  
  	i_spclocation = PQfnumber(res, spclocation);
  
! 	for (tblnum = 0; tblnum  ctx-num_tablespaces; tblnum++)
  		ctx-tablespaces[tblnum] = pg_strdup(ctx,
  	 PQgetvalue(res, tblnum, i_spclocation));
  

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers