toplevel-management: handle strdup failure

Sending a NULL string to a client would be a violation of the protocol.
This commit is contained in:
Isaac Freund 2021-01-02 20:07:47 +01:00 committed by Ilia Bozhinov
parent abcab0331f
commit 8b90d5e17f
1 changed files with 8 additions and 0 deletions

View File

@ -198,6 +198,10 @@ void wlr_foreign_toplevel_handle_v1_set_title(
struct wlr_foreign_toplevel_handle_v1 *toplevel, const char *title) { struct wlr_foreign_toplevel_handle_v1 *toplevel, const char *title) {
free(toplevel->title); free(toplevel->title);
toplevel->title = strdup(title); toplevel->title = strdup(title);
if (toplevel->title == NULL) {
wlr_log(WLR_ERROR, "failed to allocate memory for toplevel title");
return;
}
struct wl_resource *resource; struct wl_resource *resource;
wl_resource_for_each(resource, &toplevel->resources) { wl_resource_for_each(resource, &toplevel->resources) {
@ -211,6 +215,10 @@ void wlr_foreign_toplevel_handle_v1_set_app_id(
struct wlr_foreign_toplevel_handle_v1 *toplevel, const char *app_id) { struct wlr_foreign_toplevel_handle_v1 *toplevel, const char *app_id) {
free(toplevel->app_id); free(toplevel->app_id);
toplevel->app_id = strdup(app_id); toplevel->app_id = strdup(app_id);
if (toplevel->app_id == NULL) {
wlr_log(WLR_ERROR, "failed to allocate memory for toplevel app_id");
return;
}
struct wl_resource *resource; struct wl_resource *resource;
wl_resource_for_each(resource, &toplevel->resources) { wl_resource_for_each(resource, &toplevel->resources) {