summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Kozlov <xeb@mail.ru>2015-11-30 12:31:27 +0300
committerDmitry Kozlov <xeb@mail.ru>2015-11-30 12:31:27 +0300
commit8d7f1e101476998dbe9e0dd3ec2d490c34876ff1 (patch)
tree44c2983a5816493757e0c222f06f980e8c010bda
parent0227b8ba98624c54665223e9d82921f17bc01d66 (diff)
downloadaccel-ppp-8d7f1e101476998dbe9e0dd3ec2d490c34876ff1.tar.gz
accel-ppp-8d7f1e101476998dbe9e0dd3ec2d490c34876ff1.zip
pppd_compat: fixed usage of mkstamp (fixed file descriptor leak)
-rw-r--r--accel-pppd/extra/pppd_compat.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/accel-pppd/extra/pppd_compat.c b/accel-pppd/extra/pppd_compat.c
index 25223a8..2928899 100644
--- a/accel-pppd/extra/pppd_compat.c
+++ b/accel-pppd/extra/pppd_compat.c
@@ -401,7 +401,7 @@ static void write_radattr(struct pppd_compat_pd *pd, struct rad_packet_t *pack)
struct ap_session *ses = pd->ses;
struct rad_attr_t *attr;
struct rad_dict_value_t *val;
- FILE *f;
+ FILE *f = NULL;
char *fname1, *fname2 = NULL;
int i;
in_addr_t addr;
@@ -424,15 +424,22 @@ static void write_radattr(struct pppd_compat_pd *pd, struct rad_packet_t *pack)
if (ses->state == AP_STATE_ACTIVE) {
sprintf(fname1, "%s.%s", conf_radattr_prefix, ses->ifname);
sprintf(fname2, "%s_old.%s", conf_radattr_prefix, ses->ifname);
- if (rename(fname1, fname2)) {
+ if (rename(fname1, fname2))
log_ppp_warn("pppd_compat: rename: %s\n", strerror(errno));
- }
+
+ f = fopen(fname1, "w");
} else {
+ int fd;
+
sprintf(fname1, "%s.XXXXXX", conf_radattr_prefix);
- mkstemp(fname1);
+
+ fd = mkstemp(fname1);
+ if (fd < 0)
+ log_ppp_warn("pppd_compat: mkstemp: %s\n", strerror(errno));
+ else
+ f = fdopen(fd, "w");
}
- f = fopen(fname1, "w");
if (f) {
list_for_each_entry(attr, &pack->attrs, entry) {
fprintf(f, "%s ", attr->attr->name);