Fix a file descriptor leak in a prof_dump_maps() error path.
Reported by Pat Lynch.
This commit is contained in:
parent
1d1cee127a
commit
93f39f8d23
27
src/prof.c
27
src/prof.c
@ -794,6 +794,7 @@ prof_dump_ctx(bool propagate_err, prof_ctx_t *ctx, prof_bt_t *bt)
|
|||||||
static bool
|
static bool
|
||||||
prof_dump_maps(bool propagate_err)
|
prof_dump_maps(bool propagate_err)
|
||||||
{
|
{
|
||||||
|
bool ret;
|
||||||
int mfd;
|
int mfd;
|
||||||
char filename[PATH_MAX + 1];
|
char filename[PATH_MAX + 1];
|
||||||
|
|
||||||
@ -806,24 +807,34 @@ prof_dump_maps(bool propagate_err)
|
|||||||
ssize_t nread;
|
ssize_t nread;
|
||||||
|
|
||||||
if (prof_write(propagate_err, "\nMAPPED_LIBRARIES:\n") &&
|
if (prof_write(propagate_err, "\nMAPPED_LIBRARIES:\n") &&
|
||||||
propagate_err)
|
propagate_err) {
|
||||||
return (true);
|
ret = true;
|
||||||
|
goto label_return;
|
||||||
|
}
|
||||||
nread = 0;
|
nread = 0;
|
||||||
do {
|
do {
|
||||||
prof_dump_buf_end += nread;
|
prof_dump_buf_end += nread;
|
||||||
if (prof_dump_buf_end == PROF_DUMP_BUFSIZE) {
|
if (prof_dump_buf_end == PROF_DUMP_BUFSIZE) {
|
||||||
/* Make space in prof_dump_buf before read(). */
|
/* Make space in prof_dump_buf before read(). */
|
||||||
if (prof_flush(propagate_err) && propagate_err)
|
if (prof_flush(propagate_err) &&
|
||||||
return (true);
|
propagate_err) {
|
||||||
|
ret = true;
|
||||||
|
goto label_return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
nread = read(mfd, &prof_dump_buf[prof_dump_buf_end],
|
nread = read(mfd, &prof_dump_buf[prof_dump_buf_end],
|
||||||
PROF_DUMP_BUFSIZE - prof_dump_buf_end);
|
PROF_DUMP_BUFSIZE - prof_dump_buf_end);
|
||||||
} while (nread > 0);
|
} while (nread > 0);
|
||||||
close(mfd);
|
} else {
|
||||||
} else
|
ret = true;
|
||||||
return (true);
|
goto label_return;
|
||||||
|
}
|
||||||
|
|
||||||
return (false);
|
ret = false;
|
||||||
|
label_return:
|
||||||
|
if (mfd != -1)
|
||||||
|
close(mfd);
|
||||||
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
Loading…
Reference in New Issue
Block a user