open-src/lib/libXxf86vm/upstream-error-fixes.patch
changeset 1345 d5dacbb8de2b
equal deleted inserted replaced
1344:800e8c2d47f1 1345:d5dacbb8de2b
       
     1 From ef95f1c3737d9efc7d97fb1784f80ef3540a846b Mon Sep 17 00:00:00 2001
       
     2 From: Alan Coopersmith <[email protected]>
       
     3 Date: Sat, 13 Apr 2013 15:13:06 -0700
       
     4 Subject: [PATCH:libXxf86vm 1/8] When Xcalloc() returns NULL, you don't need
       
     5  to Xfree() it
       
     6 
       
     7 I have no words to explain how this ever happened.
       
     8 
       
     9 Signed-off-by: Alan Coopersmith <[email protected]>
       
    10 Reviewed-by: Peter Hutterer <[email protected]>
       
    11 ---
       
    12  src/XF86VMode.c |    5 -----
       
    13  1 file changed, 5 deletions(-)
       
    14 
       
    15 diff --git a/src/XF86VMode.c b/src/XF86VMode.c
       
    16 index 4f19cf3..c0e50e6 100644
       
    17 --- a/src/XF86VMode.c
       
    18 +++ b/src/XF86VMode.c
       
    19 @@ -256,7 +256,6 @@ XF86VidModeGetModeLine(Display* dpy, int screen, int* dotclock,
       
    20      if (modeline->privsize > 0) {
       
    21  	if (!(modeline->private = Xcalloc(modeline->privsize, sizeof(INT32)))) {
       
    22  	    _XEatData(dpy, (modeline->privsize) * sizeof(INT32));
       
    23 -	    Xfree(modeline->private);
       
    24  	    return False;
       
    25  	}
       
    26  	_XRead(dpy, (char*)modeline->private, modeline->privsize * sizeof(INT32));
       
    27 @@ -321,7 +320,6 @@ XF86VidModeGetAllModeLines(Display* dpy, int screen, int* modecount,
       
    28              _XEatData(dpy, (rep.modecount) * sizeof(xXF86OldVidModeModeInfo));
       
    29  	else
       
    30              _XEatData(dpy, (rep.modecount) * sizeof(xXF86VidModeModeInfo));
       
    31 -        Xfree(modelines);
       
    32          return False;
       
    33      }
       
    34      mdinfptr = (XF86VidModeModeInfo *) (
       
    35 @@ -353,7 +351,6 @@ XF86VidModeGetAllModeLines(Display* dpy, int screen, int* modecount,
       
    36  	            if (!(modelines[i]->private =
       
    37  			    Xcalloc(oldxmdline.privsize, sizeof(INT32)))) {
       
    38  			_XEatData(dpy, (oldxmdline.privsize) * sizeof(INT32));
       
    39 -			Xfree(modelines[i]->private);
       
    40  		    } else {
       
    41  			_XRead(dpy, (char*)modelines[i]->private,
       
    42  			     oldxmdline.privsize * sizeof(INT32));
       
    43 @@ -384,7 +381,6 @@ XF86VidModeGetAllModeLines(Display* dpy, int screen, int* modecount,
       
    44  		    if (!(modelines[i]->private =
       
    45  			    Xcalloc(xmdline.privsize, sizeof(INT32)))) {
       
    46  			_XEatData(dpy, (xmdline.privsize) * sizeof(INT32));
       
    47 -			Xfree(modelines[i]->private);
       
    48  		    } else {
       
    49  			_XRead(dpy, (char*)modelines[i]->private,
       
    50  			     xmdline.privsize * sizeof(INT32));
       
    51 @@ -1039,7 +1035,6 @@ XF86VidModeGetDotClocks(Display* dpy, int screen, int *flagsPtr,
       
    52  
       
    53      if (!(dotclocks = (int*) Xcalloc(rep.clocks, sizeof(int)))) {
       
    54          _XEatData(dpy, (rep.clocks) * 4);
       
    55 -        Xfree(dotclocks);
       
    56          return False;
       
    57      }
       
    58  
       
    59 -- 
       
    60 1.7.9.2
       
    61 
       
    62 From a89b1ad3377bfef9bab52f15f98b00f6540d531a Mon Sep 17 00:00:00 2001
       
    63 From: Alan Coopersmith <[email protected]>
       
    64 Date: Sat, 13 Apr 2013 17:40:24 -0700
       
    65 Subject: [PATCH:libXxf86vm 2/8] Improve error handling in
       
    66  XF86VidModeGetMonitor()
       
    67 
       
    68 Ensure that when we return an error we unlock the display first, and
       
    69 NULL out any pointers we freed in error cleanup.
       
    70 
       
    71 Instead of adding these fixes to every error check, instead combine
       
    72 the error handling cleanup into a single copy.
       
    73 
       
    74 Signed-off-by: Alan Coopersmith <[email protected]>
       
    75 Reviewed-by: Peter Hutterer <[email protected]>
       
    76 ---
       
    77  src/XF86VMode.c |   82 ++++++++++++++++++++++++++-----------------------------
       
    78  1 file changed, 39 insertions(+), 43 deletions(-)
       
    79 
       
    80 diff --git a/src/XF86VMode.c b/src/XF86VMode.c
       
    81 index c0e50e6..165f8ba 100644
       
    82 --- a/src/XF86VMode.c
       
    83 +++ b/src/XF86VMode.c
       
    84 @@ -856,6 +856,7 @@ XF86VidModeGetMonitor(Display* dpy, int screen, XF86VidModeMonitor* monitor)
       
    85      xXF86VidModeGetMonitorReq *req;
       
    86      CARD32 syncrange;
       
    87      int i;
       
    88 +    Bool result = True;
       
    89  
       
    90      XF86VidModeCheckExtension (dpy, info, False);
       
    91  
       
    92 @@ -875,63 +876,58 @@ XF86VidModeGetMonitor(Display* dpy, int screen, XF86VidModeMonitor* monitor)
       
    93      monitor->bandwidth = (float)rep.bandwidth / 1e6;
       
    94  #endif
       
    95      if (rep.vendorLength) {
       
    96 -	if (!(monitor->vendor = (char *)Xcalloc(rep.vendorLength + 1, 1))) {
       
    97 -	    _XEatData(dpy, (rep.nhsync + rep.nvsync) * 4 +
       
    98 -		      ((rep.vendorLength+3) & ~3) + ((rep.modelLength+3) & ~3));
       
    99 -	    return False;
       
   100 -	}
       
   101 +	monitor->vendor = Xcalloc(rep.vendorLength + 1, 1);
       
   102 +	if (monitor->vendor == NULL)
       
   103 +	    result = False;
       
   104      } else {
       
   105  	monitor->vendor = NULL;
       
   106      }
       
   107 -    if (rep.modelLength) {
       
   108 -	if (!(monitor->model = Xcalloc(rep.modelLength + 1, 1))) {
       
   109 -	    _XEatData(dpy, (rep.nhsync + rep.nvsync) * 4 +
       
   110 -		      ((rep.vendorLength+3) & ~3) + ((rep.modelLength+3) & ~3));
       
   111 -	    if (monitor->vendor)
       
   112 -		Xfree(monitor->vendor);
       
   113 -	    return False;
       
   114 -	}
       
   115 +    if (result && rep.modelLength) {
       
   116 +	monitor->model = Xcalloc(rep.modelLength + 1, 1);
       
   117 +	if (monitor->model == NULL)
       
   118 +	    result = False;
       
   119      } else {
       
   120  	monitor->model = NULL;
       
   121      }
       
   122 -    if (!(monitor->hsync = Xcalloc(rep.nhsync, sizeof(XF86VidModeSyncRange)))) {
       
   123 -	_XEatData(dpy, (rep.nhsync + rep.nvsync) * 4 +
       
   124 -		  ((rep.vendorLength+3) & ~3) + ((rep.modelLength+3) & ~3));
       
   125 -
       
   126 -	if (monitor->vendor)
       
   127 -	    Xfree(monitor->vendor);
       
   128 -	if (monitor->model)
       
   129 -	    Xfree(monitor->model);
       
   130 -	return False;
       
   131 +    if (result) {
       
   132 +	monitor->hsync = Xcalloc(rep.nhsync, sizeof(XF86VidModeSyncRange));
       
   133 +	monitor->vsync = Xcalloc(rep.nvsync, sizeof(XF86VidModeSyncRange));
       
   134 +	if ((monitor->hsync == NULL) || (monitor->vsync == NULL))
       
   135 +	    result = False;
       
   136 +    } else {
       
   137 +	monitor->hsync = monitor->vsync = NULL;
       
   138      }
       
   139 -    if (!(monitor->vsync = Xcalloc(rep.nvsync, sizeof(XF86VidModeSyncRange)))) {
       
   140 +    if (result == False) {
       
   141  	_XEatData(dpy, (rep.nhsync + rep.nvsync) * 4 +
       
   142  		  ((rep.vendorLength+3) & ~3) + ((rep.modelLength+3) & ~3));
       
   143 -	if (monitor->vendor)
       
   144 -	    Xfree(monitor->vendor);
       
   145 -	if (monitor->model)
       
   146 -	    Xfree(monitor->model);
       
   147 +	Xfree(monitor->vendor);
       
   148 +	monitor->vendor = NULL;
       
   149 +	Xfree(monitor->model);
       
   150 +	monitor->model = NULL;
       
   151  	Xfree(monitor->hsync);
       
   152 -	return False;
       
   153 -    }
       
   154 -    for (i = 0; i < rep.nhsync; i++) {
       
   155 -	_XRead(dpy, (char *)&syncrange, 4);
       
   156 -	monitor->hsync[i].lo = (float)(syncrange & 0xFFFF) / 100.0;
       
   157 -	monitor->hsync[i].hi = (float)(syncrange >> 16) / 100.0;
       
   158 +	monitor->hsync = NULL;
       
   159 +	Xfree(monitor->vsync);
       
   160 +	monitor->vsync = NULL;
       
   161      }
       
   162 -    for (i = 0; i < rep.nvsync; i++) {
       
   163 -	_XRead(dpy, (char *)&syncrange, 4);
       
   164 -	monitor->vsync[i].lo = (float)(syncrange & 0xFFFF) / 100.0;
       
   165 -	monitor->vsync[i].hi = (float)(syncrange >> 16) / 100.0;
       
   166 +    else {
       
   167 +	for (i = 0; i < rep.nhsync; i++) {
       
   168 +	    _XRead(dpy, (char *)&syncrange, 4);
       
   169 +	    monitor->hsync[i].lo = (float)(syncrange & 0xFFFF) / 100.0;
       
   170 +	    monitor->hsync[i].hi = (float)(syncrange >> 16) / 100.0;
       
   171 +	}
       
   172 +	for (i = 0; i < rep.nvsync; i++) {
       
   173 +	    _XRead(dpy, (char *)&syncrange, 4);
       
   174 +	    monitor->vsync[i].lo = (float)(syncrange & 0xFFFF) / 100.0;
       
   175 +	    monitor->vsync[i].hi = (float)(syncrange >> 16) / 100.0;
       
   176 +	}
       
   177 +	if (rep.vendorLength)
       
   178 +	    _XReadPad(dpy, monitor->vendor, rep.vendorLength);
       
   179 +	if (rep.modelLength)
       
   180 +	    _XReadPad(dpy, monitor->model, rep.modelLength);
       
   181      }
       
   182 -    if (rep.vendorLength)
       
   183 -	_XReadPad(dpy, monitor->vendor, rep.vendorLength);
       
   184 -    if (rep.modelLength)
       
   185 -	_XReadPad(dpy, monitor->model, rep.modelLength);
       
   186 -
       
   187      UnlockDisplay(dpy);
       
   188      SyncHandle();
       
   189 -    return True;
       
   190 +    return result;
       
   191  }
       
   192  
       
   193  Bool
       
   194 -- 
       
   195 1.7.9.2
       
   196 
       
   197 From 8ed00bd0a7c44c7fece687e2566d920ea74ef809 Mon Sep 17 00:00:00 2001
       
   198 From: Alan Coopersmith <[email protected]>
       
   199 Date: Sat, 13 Apr 2013 17:52:12 -0700
       
   200 Subject: [PATCH:libXxf86vm 3/8] Unlock display before returning alloc error
       
   201  in XF86VidModeGetModeLine()
       
   202 
       
   203 Signed-off-by: Alan Coopersmith <[email protected]>
       
   204 Reviewed-by: Peter Hutterer <[email protected]>
       
   205 ---
       
   206  src/XF86VMode.c |   12 +++++++-----
       
   207  1 file changed, 7 insertions(+), 5 deletions(-)
       
   208 
       
   209 diff --git a/src/XF86VMode.c b/src/XF86VMode.c
       
   210 index 165f8ba..28c79c1 100644
       
   211 --- a/src/XF86VMode.c
       
   212 +++ b/src/XF86VMode.c
       
   213 @@ -203,6 +203,7 @@ XF86VidModeGetModeLine(Display* dpy, int screen, int* dotclock,
       
   214      xXF86OldVidModeGetModeLineReply oldrep;
       
   215      xXF86VidModeGetModeLineReq *req;
       
   216      int majorVersion, minorVersion;
       
   217 +    Bool result = True;
       
   218  
       
   219      XF86VidModeCheckExtension (dpy, info, False);
       
   220      XF86VidModeQueryVersion(dpy, &majorVersion, &minorVersion);
       
   221 @@ -254,17 +255,18 @@ XF86VidModeGetModeLine(Display* dpy, int screen, int* dotclock,
       
   222      }
       
   223  
       
   224      if (modeline->privsize > 0) {
       
   225 -	if (!(modeline->private = Xcalloc(modeline->privsize, sizeof(INT32)))) {
       
   226 +	modeline->private = Xcalloc(modeline->privsize, sizeof(INT32));
       
   227 +	if (modeline->private == NULL) {
       
   228  	    _XEatData(dpy, (modeline->privsize) * sizeof(INT32));
       
   229 -	    return False;
       
   230 -	}
       
   231 -	_XRead(dpy, (char*)modeline->private, modeline->privsize * sizeof(INT32));
       
   232 +	    result = False;
       
   233 +	} else
       
   234 +	    _XRead(dpy, (char*)modeline->private, modeline->privsize * sizeof(INT32));
       
   235      } else {
       
   236  	modeline->private = NULL;
       
   237      }
       
   238      UnlockDisplay(dpy);
       
   239      SyncHandle();
       
   240 -    return True;
       
   241 +    return result;
       
   242  }
       
   243  
       
   244  Bool
       
   245 -- 
       
   246 1.7.9.2
       
   247 
       
   248 From 6c82906f25abcb0f8ec92bcdaf1872bd8b63ca5d Mon Sep 17 00:00:00 2001
       
   249 From: Alan Coopersmith <[email protected]>
       
   250 Date: Sat, 13 Apr 2013 17:54:45 -0700
       
   251 Subject: [PATCH:libXxf86vm 4/8] Unlock display before returning alloc error
       
   252  in XF86VidModeGetAllModeLines()
       
   253 
       
   254 Signed-off-by: Alan Coopersmith <[email protected]>
       
   255 Reviewed-by: Peter Hutterer <[email protected]>
       
   256 ---
       
   257  src/XF86VMode.c |    2 ++
       
   258  1 file changed, 2 insertions(+)
       
   259 
       
   260 diff --git a/src/XF86VMode.c b/src/XF86VMode.c
       
   261 index 28c79c1..76276b6 100644
       
   262 --- a/src/XF86VMode.c
       
   263 +++ b/src/XF86VMode.c
       
   264 @@ -322,6 +322,8 @@ XF86VidModeGetAllModeLines(Display* dpy, int screen, int* modecount,
       
   265              _XEatData(dpy, (rep.modecount) * sizeof(xXF86OldVidModeModeInfo));
       
   266  	else
       
   267              _XEatData(dpy, (rep.modecount) * sizeof(xXF86VidModeModeInfo));
       
   268 +	UnlockDisplay(dpy);
       
   269 +	SyncHandle();
       
   270          return False;
       
   271      }
       
   272      mdinfptr = (XF86VidModeModeInfo *) (
       
   273 -- 
       
   274 1.7.9.2
       
   275 
       
   276 From d0355b28dd53fba6fb29c350e090ed4a73d4c480 Mon Sep 17 00:00:00 2001
       
   277 From: Alan Coopersmith <[email protected]>
       
   278 Date: Sat, 13 Apr 2013 17:58:28 -0700
       
   279 Subject: [PATCH:libXxf86vm 5/8] Unlock display before returning alloc error
       
   280  in XF86VidModeGetDotClocks()
       
   281 
       
   282 Signed-off-by: Alan Coopersmith <[email protected]>
       
   283 Reviewed-by: Peter Hutterer <[email protected]>
       
   284 ---
       
   285  src/XF86VMode.c |   17 ++++++++++-------
       
   286  1 file changed, 10 insertions(+), 7 deletions(-)
       
   287 
       
   288 diff --git a/src/XF86VMode.c b/src/XF86VMode.c
       
   289 index 76276b6..1b907f4 100644
       
   290 --- a/src/XF86VMode.c
       
   291 +++ b/src/XF86VMode.c
       
   292 @@ -1014,6 +1014,7 @@ XF86VidModeGetDotClocks(Display* dpy, int screen, int *flagsPtr,
       
   293      xXF86VidModeGetDotClocksReq *req;
       
   294      int i, *dotclocks;
       
   295      CARD32 dotclk;
       
   296 +    Bool result = True;
       
   297  
       
   298      XF86VidModeCheckExtension (dpy, info, False);
       
   299  
       
   300 @@ -1033,19 +1034,21 @@ XF86VidModeGetDotClocks(Display* dpy, int screen, int *flagsPtr,
       
   301      *maxclocksPtr = rep.maxclocks;
       
   302      *flagsPtr     = rep.flags;
       
   303  
       
   304 -    if (!(dotclocks = (int*) Xcalloc(rep.clocks, sizeof(int)))) {
       
   305 +    dotclocks = Xcalloc(rep.clocks, sizeof(int));
       
   306 +    if (dotclocks == NULL) {
       
   307          _XEatData(dpy, (rep.clocks) * 4);
       
   308 -        return False;
       
   309 +        result = False;
       
   310      }
       
   311 -
       
   312 -    for (i = 0; i < rep.clocks; i++) {
       
   313 -        _XRead(dpy, (char*)&dotclk, 4);
       
   314 -	dotclocks[i] = dotclk;
       
   315 +    else {
       
   316 +	for (i = 0; i < rep.clocks; i++) {
       
   317 +	    _XRead(dpy, (char*)&dotclk, 4);
       
   318 +	    dotclocks[i] = dotclk;
       
   319 +	}
       
   320      }
       
   321      *clocksPtr = dotclocks;
       
   322      UnlockDisplay(dpy);
       
   323      SyncHandle();
       
   324 -    return True;
       
   325 +    return result;
       
   326  }
       
   327  
       
   328  Bool
       
   329 -- 
       
   330 1.7.9.2
       
   331