From: Zbigniew Jędrzejewski-Szmek Date: Mon, 28 Oct 2024 12:45:40 +0000 (+0100) Subject: qrcode-util: avoid memleak in error path X-Git-Tag: v257-rc1~95^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=439306da8b3962f683f5359c461d1669c070f377;p=thirdparty%2Fsystemd.git qrcode-util: avoid memleak in error path --- diff --git a/src/shared/qrcode-util.c b/src/shared/qrcode-util.c index afb2875aa06..da88d80d03c 100644 --- a/src/shared/qrcode-util.c +++ b/src/shared/qrcode-util.c @@ -173,6 +173,8 @@ static void write_qrcode(FILE *output, QRcode *qr, unsigned int row, unsigned in fflush(output); } +DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(QRcode*, sym_QRcode_free, NULL); + int print_qrcode_full( FILE *out, const char *header, @@ -183,7 +185,6 @@ int print_qrcode_full( unsigned tty_height, bool check_tty) { - QRcode* qr; int r; /* If this is not a UTF-8 system or ANSI colors aren't supported/disabled don't print any QR @@ -197,7 +198,8 @@ int print_qrcode_full( if (r < 0) return r; - qr = sym_QRcode_encodeString(string, 0, QR_ECLEVEL_L, QR_MODE_8, 1); + _cleanup_(sym_QRcode_freep) QRcode *qr = + sym_QRcode_encodeString(string, 0, QR_ECLEVEL_L, QR_MODE_8, 1); if (!qr) return log_oom_debug(); @@ -231,7 +233,6 @@ int print_qrcode_full( write_qrcode(out, qr, row, column); fputc('\n', out); - sym_QRcode_free(qr); return 0; } #endif