qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 03/11] util/selfmap: Discard mapping on error


From: Richard Henderson
Subject: Re: [PATCH 03/11] util/selfmap: Discard mapping on error
Date: Tue, 13 Jul 2021 10:10:16 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0

On 7/13/21 9:06 AM, Eric Blake wrote:
                  e->dev = g_strdup(fields[3]);

e->dev now contains malloc'd memory...

-                errors += qemu_strtou64(fields[4], NULL, 10, &e->inode);
+                errors |= qemu_strtou64(fields[4], NULL, 10, &e->inode);

...and if this qemu_strtou64 fails...

- /*
-                 * The last field may have leading spaces which we
-                 * need to strip.
-                 */
-                if (g_strv_length(fields) == 6) {
-                    e->path = g_strdup(g_strchug(fields[5]));
+                if (!errors) {
+                    /*
+                     * The last field may have leading spaces which we
+                     * need to strip.
+                     */
+                    if (g_strv_length(fields) == 6) {
+                        e->path = g_strdup(g_strchug(fields[5]));
+                    }
+                    map_info = g_slist_prepend(map_info, e);
+                } else {
+                    g_free(e);

...you've now leaked it.  Oops.

Yep, thanks.


r~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]