Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
f1d0e64f
Commit
f1d0e64f
authored
Aug 29, 1998
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent file descriptor leak from failed COPY.
parent
88800aac
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
6 deletions
+16
-6
src/backend/commands/copy.c
src/backend/commands/copy.c
+16
-6
No files found.
src/backend/commands/copy.c
View file @
f1d0e64f
...
...
@@ -6,7 +6,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.5
6 1998/08/29 05:27:15
momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.5
7 1998/08/29 18:19:59
momjian Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -108,12 +108,21 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
the class.
----------------------------------------------------------------------------*/
FILE
*
fp
;
static
FILE
*
fp
;
/* static for cleanup */
static
bool
file_opened
=
false
;
/* static for cleanup */
Relation
rel
;
extern
char
*
UserName
;
/* defined in global.c */
const
AclMode
required_access
=
from
?
ACL_WR
:
ACL_RD
;
int
result
;
/*
* Close previous file opened for COPY but failed with elog().
* There should be a better way, but would not be modular.
* Prevents file descriptor leak. bjm 1998/08/29
*/
if
(
file_opened
)
FreeFile
(
fp
);
rel
=
heap_openr
(
relname
);
if
(
rel
==
NULL
)
elog
(
ERROR
,
"COPY command failed. Class %s "
...
...
@@ -146,14 +155,13 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
}
else
{
/* if we elog() out, the file stays open */
fp
=
AllocateFile
(
filename
,
"r"
);
if
(
fp
==
NULL
)
elog
(
ERROR
,
"COPY command, running in backend with "
"effective uid %d, could not open file '%s' for "
"reading. Errno = %s (%d)."
,
geteuid
(),
filename
,
strerror
(
errno
),
errno
);
/* Above should not return */
file_opened
=
true
;
}
CopyFrom
(
rel
,
binary
,
oids
,
fp
,
delim
);
}
...
...
@@ -174,7 +182,6 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
mode_t
oumask
;
/* Pre-existing umask value */
oumask
=
umask
((
mode_t
)
0
);
/* if we elog() out, the file stays open */
fp
=
AllocateFile
(
filename
,
"w"
);
umask
(
oumask
);
if
(
fp
==
NULL
)
...
...
@@ -182,12 +189,15 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
"effective uid %d, could not open file '%s' for "
"writing. Errno = %s (%d)."
,
geteuid
(),
filename
,
strerror
(
errno
),
errno
);
/* Above should not return */
file_opened
=
true
;
}
CopyTo
(
rel
,
binary
,
oids
,
fp
,
delim
);
}
if
(
!
pipe
)
{
FreeFile
(
fp
);
file_opened
=
false
;
}
else
if
(
!
from
&&
!
binary
)
{
fputs
(
"
\\
.
\n
"
,
fp
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment