1- /* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.45 2008/12/1515:34:07 meskes Exp $ */
1+ /* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.46 2008/12/1519:07:48 tgl Exp $ */
22
33#define POSTGRES_ECPG_INTERNAL
44#include "postgres_fe.h"
@@ -242,31 +242,36 @@ ecpg_log(const char *format,...)
242242{
243243va_list ap ;
244244struct sqlca_t * sqlca = ECPGget_sqlca ();
245- int bufsize = strlen ( format ) + 100 ;
246- char * f = ( char * ) malloc ( bufsize ),
247- * intl_format ;
245+ const char * intl_format ;
246+ int bufsize ;
247+ char * fmt ;
248248
249- if (!simple_debug || f == NULL )
249+ if (!simple_debug )
250250return ;
251251
252252/* internationalize the error message string */
253253intl_format = ecpg_gettext (format );
254254
255255/*
256- *regression tests set this environment variable to get the same
257- *output for every run .
256+ *Insert PID into the format, unless ecpg_internal_regression_mode is
257+ *set (regression tests want unchanging output) .
258258 */
259+ bufsize = strlen (intl_format )+ 100 ;
260+ fmt = (char * )malloc (bufsize );
261+ if (fmt == NULL )
262+ return ;
263+
259264if (ecpg_internal_regression_mode )
260- snprintf (f ,bufsize ,"[NO_PID]: %s" ,intl_format );
265+ snprintf (fmt ,bufsize ,"[NO_PID]: %s" ,intl_format );
261266else
262- snprintf (f ,bufsize ,"[%d]: %s" , (int )getpid (),intl_format );
267+ snprintf (fmt ,bufsize ,"[%d]: %s" , (int )getpid (),intl_format );
263268
264269#ifdef ENABLE_THREAD_SAFETY
265270pthread_mutex_lock (& debug_mutex );
266271#endif
267272
268273va_start (ap ,format );
269- vfprintf (debugstream ,f ,ap );
274+ vfprintf (debugstream ,fmt ,ap );
270275va_end (ap );
271276
272277/* dump out internal sqlca variables */
@@ -280,7 +285,7 @@ ecpg_log(const char *format,...)
280285pthread_mutex_unlock (& debug_mutex );
281286#endif
282287
283- free (f );
288+ free (fmt );
284289}
285290
286291void