From de106747b6f456286429b8c40bff3edd0b9af771 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Mon, 18 Dec 2017 11:29:34 +0100 Subject: [PATCH] Improve main() error handling Parse the command-line arguments first, and do not ignore avformat network init failure. At the end, deinit the avformat network. --- app/src/scrcpy.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/src/scrcpy.c b/app/src/scrcpy.c index 8c7b5c79..67426a5f 100644 --- a/app/src/scrcpy.c +++ b/app/src/scrcpy.c @@ -47,9 +47,7 @@ int parse_args(struct args *args, int argc, char *argv[]) { } int main(int argc, char *argv[]) { - av_register_all(); - avformat_network_init(); - SDL_LogSetAllPriority(SDL_LOG_PRIORITY_DEBUG); + int res; struct args args = { .serial = NULL, @@ -59,5 +57,17 @@ int main(int argc, char *argv[]) { return 1; } - return show_screen(args.serial, args.port) ? 0 : 1; + av_register_all(); + + if (avformat_network_init()) { + return 1; + } + + SDL_LogSetAllPriority(SDL_LOG_PRIORITY_DEBUG); + + res = show_screen(args.serial, args.port) ? 0 : 1; + + avformat_network_deinit(); // ignore failure + + return res; }