projects
/
mmh
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
c4517ca
)
Fix FILE resource leaks in uip/distsbr.c
author
Dmitry Bogatov
<KAction@gnu.org>
Sat, 27 Aug 2016 08:37:28 +0000
(11:37 +0300)
committer
Philipp Takacs
<philipp@bureaucracy.de>
Sat, 27 Aug 2016 20:39:55 +0000
(22:39 +0200)
uip/distsbr.c
patch
|
blob
|
history
diff --git
a/uip/distsbr.c
b/uip/distsbr.c
index
058875c
..
2662c02
100644
(file)
--- a/
uip/distsbr.c
+++ b/
uip/distsbr.c
@@
-35,20
+35,23
@@
distout(char *drft, char *msgnam, char *backup)
advise(backup, "unable to rename %s to",drft);
return NOTOK;
}
advise(backup, "unable to rename %s to",drft);
return NOTOK;
}
+
+ if (ready_msg(msgnam) != OK) {
+ return NOTOK;
+ }
+
if (!(ifp = fopen(backup, "r"))) {
advise(backup, "unable to read");
return NOTOK;
}
if (!(ofp = fopen(drft, "w"))) {
if (!(ifp = fopen(backup, "r"))) {
advise(backup, "unable to read");
return NOTOK;
}
if (!(ofp = fopen(drft, "w"))) {
+ fclose(ifp);
advise(drft, "unable to create temporary file");
return NOTOK;
}
chmod(drft, m_gmprot());
advise(drft, "unable to create temporary file");
return NOTOK;
}
chmod(drft, m_gmprot());
- if (ready_msg(msgnam) != OK) {
- return NOTOK;
- }
lseek(hdrfd, (off_t) 0, SEEK_SET); /* msgnam not accurate */
cpydata(hdrfd, fileno(ofp), msgnam, drft);
lseek(hdrfd, (off_t) 0, SEEK_SET); /* msgnam not accurate */
cpydata(hdrfd, fileno(ofp), msgnam, drft);
@@
-144,12
+147,14
@@
ready_msg(char *msgnam)
cp = m_mktemp2(NULL, "dist", &hdrfd, NULL);
if (!cp) {
cp = m_mktemp2(NULL, "dist", &hdrfd, NULL);
if (!cp) {
+ fclose(ifp);
advise("distsbr", "unable to create temporary file");
return NOTOK;
}
fchmod(hdrfd, 0600);
strncpy(tmpfil, cp, sizeof(tmpfil));
if ((out = dup(hdrfd)) == NOTOK || !(ofp = fdopen(out, "w"))) {
advise("distsbr", "unable to create temporary file");
return NOTOK;
}
fchmod(hdrfd, 0600);
strncpy(tmpfil, cp, sizeof(tmpfil));
if ((out = dup(hdrfd)) == NOTOK || !(ofp = fdopen(out, "w"))) {
+ fclose(ifp);
advise(NULL, "no file descriptors -- you lose big");
return NOTOK;
}
advise(NULL, "no file descriptors -- you lose big");
return NOTOK;
}