From: Avnish Chouhan Date: Tue, 28 Oct 2025 16:28:51 +0000 (+0530) Subject: term/ieee1275/serial: Fix memory leak X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5f0ffd7f575447aab4c5bb8cfc08961971e9e767;p=thirdparty%2Fgrub.git term/ieee1275/serial: Fix memory leak The grub_zalloc() allocates memory for port. If the allocation for port->name fails the function returns NULL without freeing the previously allocated port memory. This results in a memory leak. To avoid this we must free port before return. Signed-off-by: Avnish Chouhan Reviewed-by: Sudhakar Kuppusamy Reviewed-by: Daniel Kiper --- diff --git a/grub-core/term/ieee1275/serial.c b/grub-core/term/ieee1275/serial.c index ac2a8f827..b3a8a7c8c 100644 --- a/grub-core/term/ieee1275/serial.c +++ b/grub-core/term/ieee1275/serial.c @@ -236,7 +236,11 @@ add_port (struct ofserial_hash_ent *ent) + grub_strlen (ent->shortest)); port->elem = ent; if (!port->name) - return NULL; + { + grub_free (port); + return NULL; + } + ptr = grub_stpcpy (port->name, "ieee1275/"); grub_strcpy (ptr, ent->shortest);