Skip to content

Commit 5d2ad5d

Browse files
committed
vrxtx: fix uncaught exception on compress help
Eithrer `-c help` or eg. `-c lavc:help` cause a crash because those are no longer caught in main.cpp since the commit 66fa881 (25th Mar '26). The exceptions is thrown by video_rxtx constructor when video compression fails to init (also when help issued). Catched the exceptions in the constructor now and if help was issued, INIT_NOERR is returned. this fixes CID 909027 and 909028
1 parent a757fcc commit 5d2ad5d

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

src/main.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,14 +1476,11 @@ int main(int argc, char *argv[])
14761476

14771477
uv.state_video_rxtx =
14781478
video_rxtx::create(opt.video_protocol, &opt.video, &opt.common);
1479-
if (!uv.state_video_rxtx) {
1480-
int rc = EXIT_SUCCESS;
1481-
if (strcmp(opt.video_protocol, "help") != 0 &&
1482-
strcmp(opt.video.protocol_opts, "help") != 0) {
1483-
error_msg("Requested RX/TX cannot be created "
1484-
"(missing library?)\n");
1485-
rc = EXIT_FAILURE;
1486-
}
1479+
if (uv.state_video_rxtx == nullptr ||
1480+
uv.state_video_rxtx == (video_rxtx *) INIT_NOERR) {
1481+
int rc = uv.state_video_rxtx == nullptr ? EXIT_FAILURE
1482+
: EXIT_SUCCESS;
1483+
uv.state_video_rxtx = nullptr;
14871484
exit_uv(rc);
14881485
goto cleanup;
14891486
}

src/video_rxtx.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ vrxtx_get_compression(const char *video_protocol, const char *req_compression)
9090

9191
video_rxtx::video_rxtx(const char *protocol_name,
9292
const struct vrxtx_params *params,
93-
const struct common_opts *common)
93+
const struct common_opts *common) noexcept(false)
9494
: m_exporter(common->exporter)
9595
{
9696
module_init_default(&m_sender_mod);
@@ -128,7 +128,9 @@ video_rxtx::~video_rxtx() noexcept
128128
send(NULL);
129129
compress_pop(m_compression);
130130
}
131-
m_impl_funcs->done(m_impl_state);
131+
if (m_impl_funcs != nullptr && m_impl_state != nullptr) {
132+
m_impl_funcs->done(m_impl_state);
133+
}
132134
compress_done(m_compression);
133135
module_done(&m_receiver_mod);
134136
module_done(&m_sender_mod);
@@ -242,16 +244,35 @@ void *video_rxtx::sender_loop() {
242244
return NULL;
243245
}
244246

247+
/**
248+
* @retval nullptr if video_rxtx initialization failed
249+
* @retval INIT_NOERR if help requested and shown (no state created,
250+
beware not to delete the INIT_NOERR ptr)
251+
* @retval other the vrxtx state
252+
*/
245253
video_rxtx *
246254
video_rxtx::create(string const &proto, const struct vrxtx_params *params,
247255
const struct common_opts *common) noexcept
248256
{
249257
auto vri = static_cast<const video_rxtx_info *>(load_library(proto.c_str(), LIBRARY_CLASS_VIDEO_RXTX, VIDEO_RXTX_ABI_VERSION));
250258
if (!vri) {
251-
return nullptr;
259+
if (proto != "help") {
260+
error_msg("Requested RX/TX cannot be created "
261+
"(missing library?)\n");
262+
return nullptr;
263+
}
264+
return (video_rxtx *) INIT_NOERR;
252265
}
253266

254-
auto *ret = new video_rxtx(proto.c_str(), params, common);
267+
video_rxtx *ret = nullptr;
268+
try {
269+
ret = new video_rxtx(proto.c_str(), params, common);
270+
} catch (const string &s) { // video compress init faillure
271+
MSG(ERROR, "%s\n", s.c_str());
272+
return nullptr;
273+
} catch (...) { // video compress init help
274+
return (video_rxtx *) INIT_NOERR;
275+
}
255276

256277
auto params_c = *params;
257278
params_c.sender_mod = &ret->m_sender_mod;
@@ -263,6 +284,9 @@ video_rxtx::create(string const &proto, const struct vrxtx_params *params,
263284
ret->m_impl_funcs = vri;
264285
if (ret->m_impl_state == nullptr) {
265286
delete ret;
287+
if (strcmp(params->protocol_opts, "help") == 0) {
288+
return (video_rxtx *) INIT_NOERR;
289+
}
266290
return nullptr;
267291
}
268292

src/video_rxtx.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ struct video_rxtx {
135135
protected:
136136
video_rxtx(const char *protocol_name,
137137
const struct vrxtx_params *params,
138-
const struct common_opts *opts);
138+
const struct common_opts *opts) noexcept(false);
139139
void check_sender_messages();
140140

141141
struct module m_sender_mod;

0 commit comments

Comments
 (0)