]> www.infradead.org Git - users/mchehab/rasdaemon.git/commitdiff
ras-mce-handler: change the test order to avoid leaked memory
authorMauro Carvalho Chehab <mchehab@redhat.com>
Tue, 28 May 2013 11:13:17 +0000 (08:13 -0300)
committerMauro Carvalho Chehab <mchehab@redhat.com>
Tue, 28 May 2013 11:13:17 +0000 (08:13 -0300)
As getdelim allocates memory, the better is to swap the
tests, or otherwise the code will allocate some memory that
will never be de-allocated.

Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
ras-mce-handler.c

index e0488d03103a1d5a77c0a856fd616c86b773f43d..614a0ebf9f240bfb45bb1a8cf9d976e38519b7b9 100644 (file)
@@ -126,7 +126,7 @@ static int detect_cpu(struct ras_events *ras)
                return errno;
        }
 
-       while (getdelim(&line, &linelen, '\n', f) > 0 && seen != CPU_ALL) {
+       while (seen != CPU_ALL && getdelim(&line, &linelen, '\n', f) > 0) {
                if (sscanf(line, "vendor_id : %63[^\n]",
                    (char *)&mce->vendor) == 1)
                        seen |= CPU_VENDOR;