@@ -40,12 +40,12 @@ struct options
4040
4141/* function prototypes */
4242void get_opts (int ,char * * ,struct options * );
43- PGconn * sql_conn (char * ,struct options * );
43+ PGconn * sql_conn (const char * ,struct options * );
4444void sql_exec_error (int );
45- int sql_exec (PGconn * ,char * ,int );
45+ int sql_exec (PGconn * ,const char * ,int );
4646void sql_exec_dumpdb (PGconn * );
4747void sql_exec_dumptable (PGconn * ,int );
48- void sql_exec_searchtable (PGconn * ,char * );
48+ void sql_exec_searchtable (PGconn * ,const char * );
4949void sql_exec_searchoid (PGconn * ,int );
5050
5151/* fuction to parse command line options and check for some usage errors. */
@@ -143,7 +143,6 @@ get_opts(int argc, char **argv, struct options * my_opts)
143143
144144/* display system tables */
145145case 'x' :
146-
147146my_opts -> systables = 1 ;
148147break ;
149148
@@ -170,7 +169,7 @@ Usage: pg_oid2name [-d database [-x] ] [-t table | -o oid] \n\
170169
171170/* establish connection with database. */
172171PGconn *
173- sql_conn (char * dbName ,struct options * my_opts )
172+ sql_conn (const char * dbName ,struct options * my_opts )
174173{
175174char * pghost ,
176175* pgport ;
@@ -183,11 +182,9 @@ sql_conn(char *dbName, struct options * my_opts)
183182
184183pghost = NULL ;
185184pgport = NULL ;
186-
187185pgoptions = NULL ;/* special options to start up the backend
188186 * server */
189187pgtty = NULL ;/* debugging tty for the backend server */
190-
191188pguser = NULL ;
192189pgpass = NULL ;
193190
@@ -225,12 +222,20 @@ sql_conn(char *dbName, struct options * my_opts)
225222fprintf (stderr ,"Connection to database '%s' failed.\n" ,dbName );
226223fprintf (stderr ,"%s" ,PQerrorMessage (conn ));
227224
228-
229225PQfinish (conn );
230226exit (1 );
231-
232227}
233228
229+ /* free data structures: not strictly necessary */
230+ if (pghost != NULL )
231+ free (pghost );
232+ if (pgport != NULL )
233+ free (pgport );
234+ if (pguser != NULL )
235+ free (pguser );
236+ if (pgpass != NULL )
237+ free (pgpass );
238+
234239/* return the conn if good */
235240return conn ;
236241}
@@ -266,7 +271,7 @@ sql_exec_error(int error_number)
266271
267272/* actual code to make call to the database and print the output data */
268273int
269- sql_exec (PGconn * conn ,char * todo ,int match )
274+ sql_exec (PGconn * conn ,const char * todo ,int match )
270275{
271276PGresult * res ;
272277
@@ -316,13 +321,11 @@ sql_exec(PGconn *conn, char *todo, int match)
316321return 0 ;
317322}
318323
319- /* dump all databasesknow by the system table */
324+ /* dump all databasesknown by the system table */
320325void
321326sql_exec_dumpdb (PGconn * conn )
322327{
323- char * todo ;
324-
325- todo = (char * )malloc (1024 );
328+ char todo [1024 ];
326329
327330/* get the oid and database name from the system pg_database table */
328331sprintf (todo ,"select oid,datname from pg_database" );
@@ -335,9 +338,7 @@ sql_exec_dumpdb(PGconn *conn)
335338void
336339sql_exec_dumptable (PGconn * conn ,int systables )
337340{
338- char * todo ;
339-
340- todo = (char * )malloc (1024 );
341+ char todo [1024 ];
341342
342343/* don't exclude the systables if this is set */
343344if (systables == 1 )
@@ -351,12 +352,10 @@ sql_exec_dumptable(PGconn *conn, int systables)
351352/* display the oid for a given tablename for whatever db we are connected
352353 to.do we want to allow %bar% in the search? Not now. */
353354void
354- sql_exec_searchtable (PGconn * conn ,char * tablename )
355+ sql_exec_searchtable (PGconn * conn ,const char * tablename )
355356{
356357int returnvalue ;
357- char * todo ;
358-
359- todo = (char * )malloc (1024 );
358+ char todo [1024 ];
360359
361360/* get the oid and tablename where the name matches tablename */
362361sprintf (todo ,"select relfilenode,relname from pg_class where relname = '%s'" ,tablename );
376375sql_exec_searchoid (PGconn * conn ,int oid )
377376{
378377int returnvalue ;
379- char * todo ;
380-
381- todo = (char * )malloc (1024 );
378+ char todo [1024 ];
382379
383380sprintf (todo ,"select relfilenode,relname from pg_class where oid = %i" ,oid );
384381