Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
f1d0e64f
Commit
f1d0e64f
authored
26 years ago
by
Bruce Momjian
Browse files
Options
Downloads
Patches
Plain Diff
Prevent file descriptor leak from failed COPY.
parent
88800aac
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/backend/commands/copy.c
+16
-6
16 additions, 6 deletions
src/backend/commands/copy.c
with
16 additions
and
6 deletions
src/backend/commands/copy.c
+
16
−
6
View file @
f1d0e64f
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
*
*
*
*
* IDENTIFICATION
* 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,
...
@@ -108,12 +108,21 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
the class.
the class.
----------------------------------------------------------------------------*/
----------------------------------------------------------------------------*/
FILE
*
fp
;
static
FILE
*
fp
;
/* static for cleanup */
static
bool
file_opened
=
false
;
/* static for cleanup */
Relation
rel
;
Relation
rel
;
extern
char
*
UserName
;
/* defined in global.c */
extern
char
*
UserName
;
/* defined in global.c */
const
AclMode
required_access
=
from
?
ACL_WR
:
ACL_RD
;
const
AclMode
required_access
=
from
?
ACL_WR
:
ACL_RD
;
int
result
;
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
);
rel
=
heap_openr
(
relname
);
if
(
rel
==
NULL
)
if
(
rel
==
NULL
)
elog
(
ERROR
,
"COPY command failed. Class %s "
elog
(
ERROR
,
"COPY command failed. Class %s "
...
@@ -146,14 +155,13 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
...
@@ -146,14 +155,13 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
}
}
else
else
{
{
/* if we elog() out, the file stays open */
fp
=
AllocateFile
(
filename
,
"r"
);
fp
=
AllocateFile
(
filename
,
"r"
);
if
(
fp
==
NULL
)
if
(
fp
==
NULL
)
elog
(
ERROR
,
"COPY command, running in backend with "
elog
(
ERROR
,
"COPY command, running in backend with "
"effective uid %d, could not open file '%s' for "
"effective uid %d, could not open file '%s' for "
"reading. Errno = %s (%d)."
,
"reading. Errno = %s (%d)."
,
geteuid
(),
filename
,
strerror
(
errno
),
errno
);
geteuid
(),
filename
,
strerror
(
errno
),
errno
);
/* Above should not return */
file_opened
=
true
;
}
}
CopyFrom
(
rel
,
binary
,
oids
,
fp
,
delim
);
CopyFrom
(
rel
,
binary
,
oids
,
fp
,
delim
);
}
}
...
@@ -174,7 +182,6 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
...
@@ -174,7 +182,6 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
mode_t
oumask
;
/* Pre-existing umask value */
mode_t
oumask
;
/* Pre-existing umask value */
oumask
=
umask
((
mode_t
)
0
);
oumask
=
umask
((
mode_t
)
0
);
/* if we elog() out, the file stays open */
fp
=
AllocateFile
(
filename
,
"w"
);
fp
=
AllocateFile
(
filename
,
"w"
);
umask
(
oumask
);
umask
(
oumask
);
if
(
fp
==
NULL
)
if
(
fp
==
NULL
)
...
@@ -182,12 +189,15 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
...
@@ -182,12 +189,15 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
"effective uid %d, could not open file '%s' for "
"effective uid %d, could not open file '%s' for "
"writing. Errno = %s (%d)."
,
"writing. Errno = %s (%d)."
,
geteuid
(),
filename
,
strerror
(
errno
),
errno
);
geteuid
(),
filename
,
strerror
(
errno
),
errno
);
/* Above should not return */
file_opened
=
true
;
}
}
CopyTo
(
rel
,
binary
,
oids
,
fp
,
delim
);
CopyTo
(
rel
,
binary
,
oids
,
fp
,
delim
);
}
}
if
(
!
pipe
)
if
(
!
pipe
)
{
FreeFile
(
fp
);
FreeFile
(
fp
);
file_opened
=
false
;
}
else
if
(
!
from
&&
!
binary
)
else
if
(
!
from
&&
!
binary
)
{
{
fputs
(
"
\\
.
\n
"
,
fp
);
fputs
(
"
\\
.
\n
"
,
fp
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment