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

Commit944a026

Browse files
committed
Fix pg_file_write() error handling.
Detect fclose() failures; given "ln -s /dev/full $PGDATA/devfull","pg_file_write('devfull', 'x', true)" now fails as it should. Don'tleak a stream when fwrite() fails. Remove a born-ineffective test thataimed to skip zero-length writes. Back-patch to 9.2 (all supportedversions).
1 parent2fd26b2 commit944a026

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

‎contrib/adminpack/adminpack.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,27 +136,22 @@ pg_file_write(PG_FUNCTION_ARGS)
136136
(ERRCODE_DUPLICATE_FILE,
137137
errmsg("file \"%s\" exists",filename)));
138138

139-
f=fopen(filename,"wb");
139+
f=AllocateFile(filename,"wb");
140140
}
141141
else
142-
f=fopen(filename,"ab");
142+
f=AllocateFile(filename,"ab");
143143

144144
if (!f)
145145
ereport(ERROR,
146146
(errcode_for_file_access(),
147147
errmsg("could not open file \"%s\" for writing: %m",
148148
filename)));
149149

150-
if (VARSIZE(data)!=0)
151-
{
152-
count=fwrite(VARDATA(data),1,VARSIZE(data)-VARHDRSZ,f);
153-
154-
if (count!=VARSIZE(data)-VARHDRSZ)
155-
ereport(ERROR,
156-
(errcode_for_file_access(),
157-
errmsg("could not write file \"%s\": %m",filename)));
158-
}
159-
fclose(f);
150+
count=fwrite(VARDATA(data),1,VARSIZE(data)-VARHDRSZ,f);
151+
if (count!=VARSIZE(data)-VARHDRSZ||FreeFile(f))
152+
ereport(ERROR,
153+
(errcode_for_file_access(),
154+
errmsg("could not write file \"%s\": %m",filename)));
160155

161156
PG_RETURN_INT64(count);
162157
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp