Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitace1b29

Browse files
committed
Fix two different copy-and-paste-os in CSV log rotation logic; one that led to
a double-pfree crash and another that effectively disabled size-based rotationfor CSV logs. Also suppress a memory leak and make some trivial cosmeticimprovements. Per bug #3901 from Chris Hoover and additional code-reading.
1 parenta794b99 commitace1b29

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

‎src/backend/postmaster/syslogger.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*
1919
*
2020
* IDENTIFICATION
21-
* $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.43 2008/01/01 19:45:51 momjian Exp $
21+
* $PostgreSQL: pgsql/src/backend/postmaster/syslogger.c,v 1.44 2008/01/25 20:42:10 tgl Exp $
2222
*
2323
*-------------------------------------------------------------------------
2424
*/
@@ -89,7 +89,7 @@ static bool pipe_eof_seen = false;
8989
staticFILE*syslogFile=NULL;
9090
staticFILE*csvlogFile=NULL;
9191
staticchar*last_file_name=NULL;
92-
staticchar*last_csvfile_name=NULL;
92+
staticchar*last_csv_file_name=NULL;
9393

9494
/*
9595
* Buffers for saving partial messages from different backends. We don't expect
@@ -345,12 +345,12 @@ SysLoggerMain(int argc, char *argv[])
345345
rotation_requested= true;
346346
size_rotation_for |=LOG_DESTINATION_STDERR;
347347
}
348-
if (csvlogFile!=NULL&&ftell(csvlogFile) >=Log_RotationSize*1024L)
348+
if (csvlogFile!=NULL&&
349+
ftell(csvlogFile) >=Log_RotationSize*1024L)
349350
{
350351
rotation_requested= true;
351352
size_rotation_for |=LOG_DESTINATION_CSVLOG;
352353
}
353-
354354
}
355355

356356
if (rotation_requested)
@@ -1056,7 +1056,8 @@ logfile_rotate(bool time_based_rotation, int size_rotation_for)
10561056
if (time_based_rotation|| (size_rotation_for&LOG_DESTINATION_STDERR))
10571057
{
10581058
if (Log_truncate_on_rotation&&time_based_rotation&&
1059-
last_file_name!=NULL&&strcmp(filename,last_file_name)!=0)
1059+
last_file_name!=NULL&&
1060+
strcmp(filename,last_file_name)!=0)
10601061
fh=fopen(filename,"w");
10611062
else
10621063
fh=fopen(filename,"a");
@@ -1084,6 +1085,8 @@ logfile_rotate(bool time_based_rotation, int size_rotation_for)
10841085
Log_RotationSize=0;
10851086
}
10861087
pfree(filename);
1088+
if (csvfilename)
1089+
pfree(csvfilename);
10871090
return;
10881091
}
10891092

@@ -1107,20 +1110,16 @@ logfile_rotate(bool time_based_rotation, int size_rotation_for)
11071110
if (last_file_name!=NULL)
11081111
pfree(last_file_name);
11091112
last_file_name=filename;
1110-
1111-
11121113
}
11131114

1114-
/*same as above, but for csv file. */
1115+
/*Same as above, but for csv file. */
11151116

1116-
if (csvlogFile!=NULL&& (
1117-
time_based_rotation||
1118-
(size_rotation_for&LOG_DESTINATION_STDERR)))
1117+
if (csvlogFile!=NULL&&
1118+
(time_based_rotation|| (size_rotation_for&LOG_DESTINATION_CSVLOG)))
11191119
{
11201120
if (Log_truncate_on_rotation&&time_based_rotation&&
1121-
last_csvfile_name!=NULL&&
1122-
strcmp(csvfilename,last_csvfile_name)!=0)
1123-
1121+
last_csv_file_name!=NULL&&
1122+
strcmp(csvfilename,last_csv_file_name)!=0)
11241123
fh=fopen(csvfilename,"w");
11251124
else
11261125
fh=fopen(csvfilename,"a");
@@ -1168,13 +1167,12 @@ logfile_rotate(bool time_based_rotation, int size_rotation_for)
11681167
#endif
11691168

11701169
/* instead of pfree'ing filename, remember it for next time */
1171-
if (last_csvfile_name!=NULL)
1172-
pfree(last_csvfile_name);
1173-
last_csvfile_name=filename;
1170+
if (last_csv_file_name!=NULL)
1171+
pfree(last_csv_file_name);
1172+
last_csv_file_name=csvfilename;
11741173
}
11751174

11761175
set_next_rotation_time();
1177-
11781176
}
11791177

11801178

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp