]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
term/ieee1275/serial: Fix memory leak
authorAvnish Chouhan <avnish@linux.ibm.com>
Tue, 28 Oct 2025 16:28:51 +0000 (21:58 +0530)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 6 Nov 2025 14:31:43 +0000 (15:31 +0100)
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 <avnish@linux.ibm.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/term/ieee1275/serial.c

index ac2a8f8279d343146797d32c6265b5165693c99f..b3a8a7c8ce9410fb8a2119cd3ee6c39e8bfc2dc5 100644 (file)
@@ -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);