Skip to contentSkip to conversation

xenmon: close qos_fd when finished with it in alloc_qos_data

PATCH In review Ian Campbell 2 participants 5 messages Feb 10, 2016 – Feb 11, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 xenmon: close qos_fd when finished with it in alloc_qos_data

Otherwise the fd is leaked. NB the mmap'd memory in the global cpu_qos_data[n] is not affected by closing the underlying fd.

Compile tested only.

CID: 1055930

---
 tools/xenmon/xenbaked.c | 1 +
 1 file changed, 1 insertion(+)
tools/xenmon/xenbaked.c +1 -0
index eacacb0..782f0c1 100644
@@ -689,6 +689,7 @@ static void alloc_qos_data(int ncpu)
         cpu_qos_data[n] = new_qos;
     }
     free(dummy);
+    close(qos_fd);
     new_qos = NULL;
 }
 
Signature · 1 line
2.1.4
#1 lore raw

PATCH 2/2 xenmon: initialise dummy array

This is just used to expand the shared backing file to the expected size (whether this is actually necessary I'm not sure). Rather than leaking some small amount of the processes' heap set the array to zeroes.

While at it add a check that the malloc succeeded before using the result.

Compile tested only.

CID: 1056095 (use of uninitialised data)

---
 tools/xenmon/xenbaked.c | 5 +++++
 1 file changed, 5 insertions(+)
tools/xenmon/xenbaked.c +5 -0
index 782f0c1..3d9e0ed 100644
@@ -663,6 +663,11 @@ static void alloc_qos_data(int ncpu)
     }
     pgsize = getpagesize();
     dummy = malloc(pgsize);
+    if (!dummy) {
+        PERROR("malloc");
+        exit(EXIT_FAILURE);
+    }
+    memset(dummy, 0, pgsize);
 
     for (n=0; n<ncpu; n++) {
 
Signature · 1 line
2.1.4
Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] xenmon: initialise dummy array

Quoted 5 lines · Ian Campbell

This is just used to expand the shared backing file to the expected size (whether this is actually necessary I'm not sure). Rather than leaking some small amount of the processes' heap set the array to zeroes.

Quoted 8 lines

While at it add a check that the malloc succeeded before using the result.

Compile tested only.

CID: 1056095 (use of uninitialised data)

Quoted 23 lines
---
 tools/xenmon/xenbaked.c | 5 +++++
 1 file changed, 5 insertions(+)
tools/xenmon/xenbaked.c +5 -0
index 782f0c1..3d9e0ed 100644
@@ -663,6 +663,11 @@ static void alloc_qos_data(int ncpu)
     }
     pgsize = getpagesize();
     dummy = malloc(pgsize);
+    if (!dummy) {
+        PERROR("malloc");
+        exit(EXIT_FAILURE);
+    }
+    memset(dummy, 0, pgsize);
 
     for (n=0; n<ncpu; n++) {
 
Signature · 1 line
2.1.4
Acked-by on v1 1/2
#3 lore raw
In reply to Ian Campbell
Quoted 8 lines · Ian Campbell

Otherwise the fd is leaked. NB the mmap'd memory in the global cpu_qos_data[n] is not affected by closing the underlying fd.

Compile tested only.

CID: 1055930

Quoted 19 lines
---
 tools/xenmon/xenbaked.c | 1 +
 1 file changed, 1 insertion(+)
tools/xenmon/xenbaked.c +1 -0
index eacacb0..782f0c1 100644
@@ -689,6 +689,7 @@ static void alloc_qos_data(int ncpu)
         cpu_qos_data[n] = new_qos;
     }
     free(dummy);
+    close(qos_fd);
     new_qos = NULL;
 }
 
Signature · 1 line
2.1.4