(!1975) glamor: fix segfault on calloc() failure
calloc() can always fail, so we need to prepared for this, instead of just blindly segfault'ing. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
		
							parent
							
								
									a29d4fd283
								
							
						
					
					
						commit
						d3d3d18d0a
					
				| 
						 | 
					@ -82,6 +82,10 @@ __glamor_compute_clipped_regions(int block_w,
 | 
				
			||||||
    clipped_regions = calloc((end_block_x - start_block_x + 1)
 | 
					    clipped_regions = calloc((end_block_x - start_block_x + 1)
 | 
				
			||||||
                             * (end_block_y - start_block_y + 1),
 | 
					                             * (end_block_y - start_block_y + 1),
 | 
				
			||||||
                             sizeof(*clipped_regions));
 | 
					                             sizeof(*clipped_regions));
 | 
				
			||||||
 | 
					    if (!clipped_regions) {
 | 
				
			||||||
 | 
					        *n_region = 0;
 | 
				
			||||||
 | 
					        return NULL;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    DEBUGF("startx %d starty %d endx %d endy %d \n",
 | 
					    DEBUGF("startx %d starty %d endx %d endy %d \n",
 | 
				
			||||||
           start_x, start_y, end_x, end_y);
 | 
					           start_x, start_y, end_x, end_y);
 | 
				
			||||||
| 
						 | 
					@ -222,6 +226,11 @@ glamor_compute_clipped_regions_ext(PixmapPtr pixmap,
 | 
				
			||||||
                               inner_block_w)
 | 
					                               inner_block_w)
 | 
				
			||||||
                            * ((block_h + inner_block_h - 1) /
 | 
					                            * ((block_h + inner_block_h - 1) /
 | 
				
			||||||
                               inner_block_h), sizeof(*result_regions));
 | 
					                               inner_block_h), sizeof(*result_regions));
 | 
				
			||||||
 | 
					    if (!result_regions) {
 | 
				
			||||||
 | 
					        *n_region = 0;
 | 
				
			||||||
 | 
					        return NULL;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    k = 0;
 | 
					    k = 0;
 | 
				
			||||||
    for (i = 0; i < *n_region; i++) {
 | 
					    for (i = 0; i < *n_region; i++) {
 | 
				
			||||||
        x = box_array[clipped_regions[i].block_idx].x1;
 | 
					        x = box_array[clipped_regions[i].block_idx].x1;
 | 
				
			||||||
| 
						 | 
					@ -368,6 +377,11 @@ _glamor_compute_clipped_regions(PixmapPtr pixmap,
 | 
				
			||||||
    DEBUGRegionPrint(region);
 | 
					    DEBUGRegionPrint(region);
 | 
				
			||||||
    if (glamor_pixmap_priv_is_small(pixmap_priv)) {
 | 
					    if (glamor_pixmap_priv_is_small(pixmap_priv)) {
 | 
				
			||||||
        clipped_regions = calloc(1, sizeof(*clipped_regions));
 | 
					        clipped_regions = calloc(1, sizeof(*clipped_regions));
 | 
				
			||||||
 | 
					        if (!clipped_regions) {
 | 
				
			||||||
 | 
					            *n_region = 0;
 | 
				
			||||||
 | 
					            return NULL;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        clipped_regions[0].region = RegionCreate(NULL, 1);
 | 
					        clipped_regions[0].region = RegionCreate(NULL, 1);
 | 
				
			||||||
        clipped_regions[0].block_idx = 0;
 | 
					        clipped_regions[0].block_idx = 0;
 | 
				
			||||||
        RegionCopy(clipped_regions[0].region, region);
 | 
					        RegionCopy(clipped_regions[0].region, region);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue