From a442374107b4c7c2dde9d71b5a105679c560b35c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
Date: Mon, 28 Oct 2024 13:45:40 +0100
Subject: [PATCH 0978/1160] qrcode-util: avoid memleak in error path
(cherry picked from commit 439306da8b3962f683f5359c461d1669c070f377)
(cherry picked from commit bbda54c6717a0a079741ded27401d7de363f9d26)
src/shared/qrcode-util.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
@@ -167,6 +167,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,
@@ -177,7 +179,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
@@ -191,7 +192,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();
@@ -225,7 +227,6 @@ int print_qrcode_full(
write_qrcode(out, qr, row, column);
fputc('\n', out);
- sym_QRcode_free(qr);
return 0;
}
#endif
--
2.33.0