Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
ffmpeg
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefan Westerfeld
ffmpeg
Commits
2bc3be02
Commit
2bc3be02
authored
Jun 01, 2024
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avfilter/asubprocess: cleanup subprocess in uninit
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
a80a1199
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
12 deletions
+39
-12
af_asubprocess.c
libavfilter/af_asubprocess.c
+39
-12
No files found.
libavfilter/af_asubprocess.c
View file @
2bc3be02
...
...
@@ -98,11 +98,36 @@ static void spb_free_all(SPB **spbp)
*
spbp
=
NULL
;
}
static
void
close_pipe
(
int
*
pipefd
)
{
close
(
pipefd
[
0
]);
close
(
pipefd
[
1
]);
}
static
void
sp_cleanup
(
SP
*
sp
)
{
if
(
sp
->
input_pipe
>=
0
)
close
(
sp
->
input_pipe
);
if
(
sp
->
output_pipe
>=
0
)
close
(
sp
->
output_pipe
);
if
(
!
sp
->
done
)
{
int
status
;
waitpid
(
sp
->
pid
,
&
status
,
0
);
}
spb_free_all
(
&
sp
->
unused_buffers
);
spb_free_all
(
&
sp
->
out_buffers
);
av_free
(
sp
);
}
static
int
sp_new
(
AVFilterContext
*
ctx
)
{
ASubProcessContext
*
s
=
ctx
->
priv
;
SP
*
sp
=
av_mallocz
(
sizeof
(
SP
))
;
SP
*
sp
;
int
output_pipe
[
2
];
int
input_pipe
[
2
];
int
i
;
...
...
@@ -116,11 +141,14 @@ sp_new(AVFilterContext *ctx)
if
(
pipe
(
input_pipe
)
<
0
)
{
int
ret
=
AVERROR
(
errno
);
av_log
(
ctx
,
AV_LOG_ERROR
,
"Failed create subprocess input pipe: %s.
\n
"
,
strerror
(
errno
));
close_pipe
(
output_pipe
);
return
ret
;
}
pid
=
fork
();
if
(
pid
<
0
)
{
int
ret
=
AVERROR
(
errno
);
close_pipe
(
input_pipe
);
close_pipe
(
output_pipe
);
av_log
(
ctx
,
AV_LOG_ERROR
,
"Failed to fork() subprocess: %s.
\n
"
,
strerror
(
errno
));
return
ret
;
}
...
...
@@ -133,15 +161,16 @@ sp_new(AVFilterContext *ctx)
perror
(
"asubprocess dup2() for stdout failed"
);
exit
(
EXIT_FAILURE
);
}
close
(
output_pipe
[
1
]);
close
(
output_pipe
[
0
]);
close
(
input_pipe
[
1
]);
close
(
input_pipe
[
0
]);
close_pipe
(
input_pipe
);
close_pipe
(
output_pipe
);
execl
(
"/bin/sh"
,
"/bin/sh"
,
"-c"
,
s
->
command
,
NULL
);
perror
(
"asubprocess execl() failed"
);
exit
(
EXIT_FAILURE
);
}
sp
=
av_mallocz
(
sizeof
(
SP
));
sp
->
pid
=
pid
;
sp
->
input_pipe
=
input_pipe
[
1
];
sp
->
output_pipe
=
output_pipe
[
0
];
close
(
input_pipe
[
0
]);
close
(
output_pipe
[
1
]);
...
...
@@ -150,6 +179,7 @@ sp_new(AVFilterContext *ctx)
i
=
fcntl
(
output_pipe
[
0
],
F_GETFL
);
if
(
i
<
0
)
{
int
ret
=
AVERROR
(
errno
);
sp_cleanup
(
sp
);
av_log
(
ctx
,
AV_LOG_ERROR
,
"Failed to get output pipe flags: %s.
\n
"
,
strerror
(
errno
));
return
ret
;
}
...
...
@@ -160,14 +190,13 @@ sp_new(AVFilterContext *ctx)
i
=
fcntl
(
input_pipe
[
1
],
F_GETFL
);
if
(
i
<
0
)
{
int
ret
=
AVERROR
(
errno
);
sp_cleanup
(
sp
);
av_log
(
ctx
,
AV_LOG_ERROR
,
"Failed to get input pipe flags: %s.
\n
"
,
strerror
(
errno
));
return
ret
;
}
i
|=
O_NONBLOCK
;
fcntl
(
input_pipe
[
1
],
F_SETFL
,
i
);
sp
->
input_pipe
=
input_pipe
[
1
];
sp
->
output_pipe
=
output_pipe
[
0
];
s
->
sp
=
sp
;
return
0
;
}
...
...
@@ -410,11 +439,9 @@ static av_cold void uninit(AVFilterContext *ctx)
{
ASubProcessContext
*
s
=
ctx
->
priv
;
if
(
s
->
sp
)
{
spb_free_all
(
&
s
->
sp
->
unused_buffers
);
spb_free_all
(
&
s
->
sp
->
out_buffers
);
av_freep
(
&
s
->
sp
);
}
if
(
s
->
sp
)
sp_cleanup
(
s
->
sp
);
ff_framequeue_free
(
&
s
->
frame_queue
);
av_freep
(
&
s
->
sample_buffer
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment