]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix pg_upgrade to remove malloc(0) call.
authorBruce Momjian <bruce@momjian.us>
Wed, 16 Jun 2010 19:43:11 +0000 (19:43 +0000)
committerBruce Momjian <bruce@momjian.us>
Wed, 16 Jun 2010 19:43:11 +0000 (19:43 +0000)
contrib/pg_upgrade/tablespace.c

index 302eb0d1cb173ae5dad45619311405236ce70c78..9eda197f06e7b366f70b5b4053d89413158da840 100644 (file)
@@ -38,7 +38,6 @@ get_tablespace_paths(migratorContext *ctx)
 {
        PGconn     *conn = connectToServer(ctx, "template1", CLUSTER_OLD);
        PGresult   *res;
-       int                     ntups;
        int                     tblnum;
        int                     i_spclocation;
 
@@ -48,12 +47,15 @@ get_tablespace_paths(migratorContext *ctx)
                                                        "WHERE  spcname != 'pg_default' AND "
                                                        "               spcname != 'pg_global'");
 
-       ctx->num_tablespaces = ntups = PQntuples(res);
-       ctx->tablespaces = (char **) pg_malloc(ctx, ntups * sizeof(char *));
+       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 < ntups; tblnum++)
+       for (tblnum = 0; tblnum < ctx->num_tablespaces; tblnum++)
                ctx->tablespaces[tblnum] = pg_strdup(ctx,
                                                                         PQgetvalue(res, tblnum, i_spclocation));