[PATCH v3 xf86-video-nested 06/10] Fix several memory leaks detected by valgrind.

Laércio de Sousa laerciosousa at sme-mogidascruzes.sp.gov.br
Mon Nov 9 09:22:34 PST 2015


Signed-off-by: Laércio de Sousa <laerciosousa at sme-mogidascruzes.sp.gov.br>
---
 src/driver.c       |  6 ++++++
 src/nested_input.c | 23 +++++++++++++++++------
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/src/driver.c b/src/driver.c
index 74c7d93..cafa895 100644
--- a/src/driver.c
+++ b/src/driver.c
@@ -580,6 +580,11 @@ NestedAddMode(ScrnInfoPtr pScrn, int width, int height) {
 // to force the initialization to wait until the input core is initialized.
 static CARD32
 NestedMouseTimer(OsTimerPtr timer, CARD32 time, pointer arg) {
+    if (timer) {
+        TimerFree(timer);
+        timer = NULL;
+    }
+
     NestedInputLoadDriver(arg);
     return 0;
 }
@@ -713,6 +718,7 @@ NestedCloseScreen(CLOSE_SCREEN_ARGS_DECL) {
     NestedClientCloseScreen(PCLIENTDATA(pScrn));
 
     pScreen->CloseScreen = PNESTED(pScrn)->CloseScreen;
+
     return (*pScreen->CloseScreen)(CLOSE_SCREEN_ARGS);
 }
 
diff --git a/src/nested_input.c b/src/nested_input.c
index 0d584c8..2083c77 100644
--- a/src/nested_input.c
+++ b/src/nested_input.c
@@ -189,6 +189,7 @@ _nested_input_init_keyboard(DeviceIntPtr device) {
 }
 static int
 _nested_input_init_buttons(DeviceIntPtr device) {
+    int ret = Success;
     InputInfoPtr pInfo = device->public.devicePrivate;
     CARD8       *map;
     Atom         buttonLabels[NUM_MOUSE_BUTTONS] = {0};
@@ -201,12 +202,11 @@ _nested_input_init_buttons(DeviceIntPtr device) {
 
     if (!InitButtonClassDeviceStruct(device, NUM_MOUSE_BUTTONS, buttonLabels, map)) {
         xf86Msg(X_ERROR, "%s: Failed to register buttons.\n", pInfo->name);
-        
-        free(map);
-        return BadAlloc;
+        ret = BadAlloc;
     }
 
-    return Success;
+    free(map);
+    return ret;
 }
 
 static int
@@ -233,6 +233,11 @@ nested_input_on(OsTimerPtr timer, CARD32 time, pointer arg) {
     DeviceIntPtr device = arg;
     InputInfoPtr pInfo = device->public.devicePrivate;
     NestedInputDevicePtr pNestedInput = pInfo->private;
+    
+    if (timer) {
+        TimerFree(timer);
+        timer = NULL;
+    }
 
     if(device->public.on)
     {
@@ -293,6 +298,12 @@ NestedInputControl(DeviceIntPtr device, int what) {
 static CARD32
 nested_input_ready(OsTimerPtr timer, CARD32 time, pointer arg) {
     NestedClientPrivatePtr clientData = arg;
+    
+    if (timer) {
+        TimerFree(timer);
+        timer = NULL;
+    }
+
     NestedClientCheckEvents(clientData);
     return 0;
 }
@@ -344,8 +355,8 @@ NestedInputLoadDriver(NestedClientPrivatePtr clientData) {
 
     // Create input options for our invocation to NewInputDeviceRequest.   
     InputOption* options = NULL;
-    options = input_option_new(options, strdup("identifier"), strdup("nestedinput"));
-    options = input_option_new(options, strdup("driver"), strdup("nestedinput"));
+    options = input_option_new(options, "identifier", "Nested virtual generic input device");
+    options = input_option_new(options, "driver", "nestedinput");
     
     // Invoke NewInputDeviceRequest to call the PreInit function of
     // the driver.
-- 
2.1.4



More information about the xorg-devel mailing list