Skip to contentSkip to conversation

tools/libxl/libxl_cpuid.c: Fix leak of resstr on error path

PATCH Applied PRAMOD DEVENDRA 3 participants 3 messages Mar 16, 2015 – Mar 18, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 2/3 tools/libxl/libxl_cpuid.c: Fix leak of resstr on error path

From: Pramod Devendra <[email protected]>

CC Ian Jackson <[email protected]>
CC Stefano Stabellini <[email protected]>
CC Ian Campbell <[email protected]>
CC Wei Liu <[email protected]>
---
 tools/libxl/libxl_cpuid.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
tools/libxl/libxl_cpuid.c +5 -3
index b0bdc9d..c66e912 100644
@@ -223,9 +223,6 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* str)
     }
     entry = cpuid_find_match(cpuid, flag->leaf, flag->subleaf);
     resstr = entry->policy[flag->reg - 1];
-    if (resstr == NULL) {
-        resstr = strdup("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
-    }
     num = strtoull(val, &endptr, 0);
     flags[flag->length] = 0;
     if (endptr != val) {
@@ -242,6 +239,11 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* str)
             return 3;
         }
     }
+
+    if (resstr == NULL) {
+        resstr = strdup("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
+    }
+
     /* the family and model entry is potentially split up across
      * two fields in Fn0000_0001_EAX, so handle them here separately.
      */
Signature · 1 line
1.7.10.4
Acked-by on v1 2/3
#1 lore raw
Quoted 7 lines · PRAMOD DEVENDRA

From: Pramod Devendra <[email protected]>

CC Ian Jackson <[email protected]>
CC Stefano Stabellini <[email protected]>
CC Ian Campbell <[email protected]>
CC Wei Liu <[email protected]>
Quoted 9 lines
---
 tools/libxl/libxl_cpuid.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
tools/libxl/libxl_cpuid.c +0 -0
index b0bdc9d..c66e912 100644

tools/libxl/libxl_cpuid.c int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* str) · line 228

Quoted 6 lines
tools/libxl/libxl_cpuid.c +0 -3
@@ -223,9 +223,6 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* str)
     }
     entry = cpuid_find_match(cpuid, flag->leaf, flag->subleaf);
     resstr = entry->policy[flag->reg - 1];
-    if (resstr == NULL) {
-        resstr = strdup("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
-    }

Minor nit. I would prefer "resstr = " be grouped with the code you moved. No need to resend though.

Wei.

Quoted 17 lines
tools/libxl/libxl_cpuid.c +5 -0
     num = strtoull(val, &endptr, 0);
     flags[flag->length] = 0;
     if (endptr != val) {
@@ -242,6 +239,11 @@ int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* str)
             return 3;
         }
     }
+
+    if (resstr == NULL) {
+        resstr = strdup("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
+    }
+
     /* the family and model entry is potentially split up across
      * two fields in Fn0000_0001_EAX, so handle them here separately.
      */
Signature · 1 line
1.7.10.4
Applied
#2 lore raw
Quoted 10 lines · Wei Liu
Quoted 7 lines · PRAMOD DEVENDRA

From: Pramod Devendra <[email protected]>

CC Ian Jackson <[email protected]>
CC Stefano Stabellini <[email protected]>
CC Ian Campbell <[email protected]>
CC Wei Liu <[email protected]>

Applied.

Quoted 7 lines

tools/libxl/libxl_cpuid.c int libxl_cpuid_parse_config(libxl_cpuid_policy_list *cpuid, const char* str) · line 228

Quoted 4 lines
     resstr = entry->policy[flag->reg - 1];
tools/libxl/libxl_cpuid.c +0 -3
-    if (resstr == NULL) {
-        resstr = strdup("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
-    }

Minor nit. I would prefer "resstr = " be grouped with the code you moved. No need to resend though.

Do you mean the restr = entry->... bit?