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

Laércio de Sousa laerciosousa at sme-mogidascruzes.sp.gov.br
Thu Nov 5 01:15:02 PST 2015


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

diff --git a/src/driver.c b/src/driver.c
index 74c7d93..7939ce7 100644
--- a/src/driver.c
+++ b/src/driver.c
@@ -183,6 +183,8 @@ typedef struct NestedPrivate {
     ShadowUpdateProc update;
 } NestedPrivate, *NestedPrivatePtr;
 
+OsTimerPtr timer;
+
 #define PNESTED(p) ((NestedPrivatePtr)((p)->driverPrivate))
 #define PCLIENTDATA(p) (PNESTED(p)->clientData)
 
@@ -630,7 +632,7 @@ static Bool NestedScreenInit(SCREEN_INIT_ARGS_DECL)
     
     // Schedule the NestedInputLoadDriver function to load once the
     // input core is initialized.
-    TimerSet(NULL, 0, 1, NestedMouseTimer, pNested->clientData);
+    timer = TimerSet(NULL, 0, 1, NestedMouseTimer, pNested->clientData);
 
     miClearVisualTypes();
     if (!miSetVisualTypesAndMasks(pScrn->depth,
@@ -713,6 +715,10 @@ NestedCloseScreen(CLOSE_SCREEN_ARGS_DECL) {
     NestedClientCloseScreen(PCLIENTDATA(pScrn));
 
     pScreen->CloseScreen = PNESTED(pScrn)->CloseScreen;
+    
+    if (timer != NULL)
+        free(timer);
+
     return (*pScreen->CloseScreen)(CLOSE_SCREEN_ARGS);
 }
 
diff --git a/src/nested_input.c b/src/nested_input.c
index 0d584c8..1a8ba18 100644
--- a/src/nested_input.c
+++ b/src/nested_input.c
@@ -102,6 +102,8 @@ _X_EXPORT XF86ModuleData nestedInputModuleData = {
     &NestedInputUnplug
 };
 
+static OsTimerPtr input_on_timer, read_input_timer;
+
 int
 NestedInputPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags) {
     NestedInputDevicePtr pNestedInput;
@@ -122,6 +124,7 @@ NestedInputPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags) {
 
 void
 NestedInputUnInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags) {
+    free(read_input_timer);
 }
 
 static pointer
@@ -189,6 +192,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 +205,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
@@ -270,7 +273,7 @@ NestedInputControl(DeviceIntPtr device, int what) {
                 break;
 
             device->public.on = TRUE;
-            TimerSet(NULL, 0, 1, nested_input_on, device);
+            input_on_timer = TimerSet(NULL, 0, 1, nested_input_on, device);
             break;
         case DEVICE_OFF:
             xf86Msg(X_INFO, "%s: Off.\n", pInfo->name);
@@ -282,6 +285,7 @@ NestedInputControl(DeviceIntPtr device, int what) {
             
             pInfo->fd = -1;
             device->public.on = FALSE;
+            free(input_on_timer);
             break;
         case DEVICE_CLOSE:
             break;
@@ -300,7 +304,7 @@ nested_input_ready(OsTimerPtr timer, CARD32 time, pointer arg) {
 static void 
 NestedInputReadInput(InputInfoPtr pInfo) {
     NestedInputDevicePtr pNestedInput = pInfo->private;
-    TimerSet(NULL, 0, 1, nested_input_ready, pNestedInput->clientData);
+    read_input_timer = TimerSet(NULL, 0, 1, nested_input_ready, pNestedInput->clientData);
 }
 
 #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 14
@@ -344,8 +348,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 pointer");
+    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