mirror of
				https://gitlab.freedesktop.org/wayland/wayland.git
				synced 2025-11-03 09:01:42 -05:00 
			
		
		
		
	cursor: check for memory allocation errors
Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
This commit is contained in:
		
							parent
							
								
									7d96da1e65
								
							
						
					
					
						commit
						d6c6f2977d
					
				
					 1 changed files with 13 additions and 1 deletions
				
			
		| 
						 | 
					@ -261,6 +261,11 @@ load_default_theme(struct wl_cursor_theme *theme)
 | 
				
			||||||
	theme->cursor_count = ARRAY_LENGTH(cursor_metadata);
 | 
						theme->cursor_count = ARRAY_LENGTH(cursor_metadata);
 | 
				
			||||||
	theme->cursors = malloc(theme->cursor_count * sizeof(*theme->cursors));
 | 
						theme->cursors = malloc(theme->cursor_count * sizeof(*theme->cursors));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (theme->cursors == NULL) {
 | 
				
			||||||
 | 
							theme->cursor_count = 0;
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0; i < theme->cursor_count; ++i) {
 | 
						for (i = 0; i < theme->cursor_count; ++i) {
 | 
				
			||||||
		theme->cursors[i] =
 | 
							theme->cursors[i] =
 | 
				
			||||||
			wl_cursor_create_from_data(&cursor_metadata[i], theme);
 | 
								wl_cursor_create_from_data(&cursor_metadata[i], theme);
 | 
				
			||||||
| 
						 | 
					@ -295,6 +300,8 @@ wl_cursor_create_from_xcursor_images(XcursorImages *images,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0; i < images->nimage; i++) {
 | 
						for (i = 0; i < images->nimage; i++) {
 | 
				
			||||||
		image = malloc(sizeof *image);
 | 
							image = malloc(sizeof *image);
 | 
				
			||||||
 | 
							if (image == NULL)
 | 
				
			||||||
 | 
								break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		image->theme = theme;
 | 
							image->theme = theme;
 | 
				
			||||||
		image->buffer = NULL;
 | 
							image->buffer = NULL;
 | 
				
			||||||
| 
						 | 
					@ -349,8 +356,13 @@ load_callback(XcursorImages *images, void *data)
 | 
				
			||||||
			realloc(theme->cursors,
 | 
								realloc(theme->cursors,
 | 
				
			||||||
				theme->cursor_count * sizeof theme->cursors[0]);
 | 
									theme->cursor_count * sizeof theme->cursors[0]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if (theme->cursors == NULL) {
 | 
				
			||||||
 | 
								theme->cursor_count--;
 | 
				
			||||||
 | 
								free(cursor);
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
			theme->cursors[theme->cursor_count - 1] = cursor;
 | 
								theme->cursors[theme->cursor_count - 1] = cursor;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	XcursorImagesDestroy(images);
 | 
						XcursorImagesDestroy(images);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue