=== modified file 'middle-pgsql.c'
--- middle-pgsql.c	2010-12-05 23:32:10 +0000
+++ middle-pgsql.c	2011-01-13 21:54:05 +0000
@@ -1085,26 +1085,6 @@
     }
 }
 
-/* Replace %s with prefix */
-static inline void set_prefix( const char *prefix, const char **string )
-{
-  char buffer[1024];
-  if( *string == NULL )
-      return;
-  sprintf( buffer, *string, prefix, prefix, prefix, prefix, prefix, prefix );
-  *string = strdup( buffer );
-}
-
-/* Replace %s with prefix and tablespace*/
-static inline void set_prefixtbls( const char *prefix, const char *tbls, const char **string )
-{
-  char buffer[1024];
-  if( *string == NULL )
-      return;
-  sprintf( buffer, *string, prefix, prefix, tbls );
-  *string = strdup( buffer );
-}
-
 static int build_indexes;
 
 static int pgsql_start(const struct output_options *options)

=== modified file 'output-pgsql.c'
--- output-pgsql.c	2011-01-13 13:49:52 +0000
+++ output-pgsql.c	2011-01-13 21:54:05 +0000
@@ -1141,12 +1141,8 @@
     for (i=0; i<NUM_TABLES; i++) {
         PGconn *sql_conn;
 
-        /* Substitute prefix into name of table */
-        {
-            char *temp = malloc( strlen(options->prefix) + strlen(tables[i].name) + 1 );
-            sprintf( temp, tables[i].name, options->prefix );
-            tables[i].name = temp;
-        }
+        set_prefix( options->prefix, &(tables[i].name) );
+	
         fprintf(stderr, "Setting up table: %s\n", tables[i].name);
         sql_conn = PQconnectdb(options->conninfo);
 

=== modified file 'pgsql.h'
--- pgsql.h	2008-06-05 20:09:23 +0000
+++ pgsql.h	2011-01-13 21:54:05 +0000
@@ -9,3 +9,23 @@
 int pgsql_CopyData(const char *context, PGconn *sql_conn, const char *sql);
 int pgsql_exec(PGconn *sql_conn, ExecStatusType expect, const char *fmt, ...) __attribute__ ((format (printf, 3, 4)));
 void escape(char *out, int len, const char *in);
+
+/* Replace %s with prefix */
+static inline void set_prefix( const char *prefix, const char **string )
+{
+  char buffer[1024];
+  if( *string == NULL )
+      return;
+  sprintf( buffer, *string, prefix, prefix, prefix, prefix, prefix, prefix );
+  *string = strdup( buffer );
+}
+
+/* Replace %s with prefix and tablespace*/
+static inline void set_prefixtbls( const char *prefix, const char *tbls, const char **string )
+{
+  char buffer[1024];
+  if( *string == NULL )
+      return;
+  sprintf( buffer, *string, prefix, prefix, tbls );
+  *string = strdup( buffer );
+}

