Skip to content

Commit 0954160

Browse files
samasth-norwayacmel
authored andcommitted
perf daemon: Fix file leak in daemon_session__control
The open() function returns -1 on error. The 'control' and 'ack' file descriptors are both initialized with open() and further validated with 'if' statement. 'if (!control)' would evaluate to 'true' if returned value on error were '0' but it is actually '-1'. Fixes: edcaa47 ("perf daemon: Add 'ping' command") Signed-off-by: Samasth Norway Ananda <samasth.norway.ananda@oracle.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Ian Rogers <irogers@google.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://lore.kernel.org/r/20240510003424.2016914-1-samasth.norway.ananda@oracle.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 230a7a7 commit 0954160

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tools/perf/builtin-daemon.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ static int daemon_session__control(struct daemon_session *session,
523523
session->base, SESSION_CONTROL);
524524

525525
control = open(control_path, O_WRONLY|O_NONBLOCK);
526-
if (!control)
526+
if (control < 0)
527527
return -1;
528528

529529
if (do_ack) {
@@ -532,7 +532,7 @@ static int daemon_session__control(struct daemon_session *session,
532532
session->base, SESSION_ACK);
533533

534534
ack = open(ack_path, O_RDONLY, O_NONBLOCK);
535-
if (!ack) {
535+
if (ack < 0) {
536536
close(control);
537537
return -1;
538538
}

0 commit comments

Comments
 (0)