diff options
author | Peter Eisentraut <peter_e@gmx.net> | 2017-09-22 16:50:59 -0400 |
---|---|---|
committer | Peter Eisentraut <peter_e@gmx.net> | 2017-09-23 10:05:28 -0400 |
commit | 9bf04994697dd094032d08682a25cbba7aba523f (patch) | |
tree | f1b0808a5620cc1ad7f20f279705ded076f21732 /src/backend/commands/copy.c | |
parent | dbd6099fbc7783aa167eebc15a0688a613e16635 (diff) |
Fix saving and restoring umask
In two cases, we set a different umask for some piece of code and
restore it afterwards. But if the contained code errors out, the umask
is not restored. So add TRY/CATCH blocks to fix that.
Diffstat (limited to 'src/backend/commands/copy.c')
-rw-r--r-- | src/backend/commands/copy.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 3eba9efcc63..71bec156cdb 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -1619,7 +1619,16 @@ BeginCopyTo(Relation rel, errmsg("relative path not allowed for COPY to file"))); oumask = umask(S_IWGRP | S_IWOTH); - cstate->copy_file = AllocateFile(cstate->filename, PG_BINARY_W); + PG_TRY(); + { + cstate->copy_file = AllocateFile(cstate->filename, PG_BINARY_W); + } + PG_CATCH(); + { + umask(oumask); + PG_RE_THROW(); + } + PG_END_TRY(); umask(oumask); if (cstate->copy_file == NULL) ereport(ERROR, |