Commit d0287c1d authored by Fabian Vogt's avatar Fabian Vogt

Fix leak of pipe FDs in MD RAID code

Summary:
Use pipe2 with O_CLOEXEC to not leak FDs and close the pipe completely after reading.

BUG: 378268

Test Plan:
Did not break anything here, but I don't have MD RAID.
According to the reporter this fixed the FD leak issue.

Reviewers: #plasma, mart

Reviewed By: #plasma, mart

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D13664
parent 4b191992
......@@ -215,7 +215,7 @@ void getMdadmDetail( ArrayInfo* MyArray ) {
char* mdadmStatBufP;
/* Create a pipe */
if(pipe(fd) == -1)
if(pipe2(fd, O_CLOEXEC) == -1)
{
perror("Could not create a pipe to launch mdadm.");
exit(1);
......@@ -258,6 +258,9 @@ void getMdadmDetail( ArrayInfo* MyArray ) {
if (nbytes >= 0)
mdadmStatBuf[nbytes] = '\0';
/* Close output side of pipe */
close(fd[0]);
/* Now, go through mdadmStatBuf line by line. Register monitors along the way */
sprintf( format, "%%%d[^\n]\n", (int)sizeof( lineBuf ) - 1 );
mdadmStatBufP = mdadmStatBuf;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment