summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndyZhou <zhoumy@cn.fujitsu.com>2021-12-22 16:00:59 +0800
committerAndyZhou <zhoumy@cn.fujitsu.com>2021-12-22 16:00:59 +0800
commit471a12ee38098aaac86e5a9a8e256fd88cd67c0a (patch)
tree68c4d3cef11dc27c0f990e9b07016b9d0b8132fa
parent18918978ba5c0f91f05513170c8ca57a93e96722 (diff)
agl-compositor:Add NULL check after zalloc in src directorymarlin_12.91.0marlin/12.91.012.91.0
There's no NULL check in zalloc. Add a NULL check after zalloc. And add memory free before return error. Bug-AGL: SPEC-4178 Signed-off-by: ZhouMingying <zhoumy@cn.fujitsu.com> Change-Id: Ic0e0e2007b2897a451507aed100ad01b65695383
-rw-r--r--src/compositor.c8
-rw-r--r--src/policy.c28
-rw-r--r--src/shell.c40
3 files changed, 72 insertions, 4 deletions
diff --git a/src/compositor.c b/src/compositor.c
index 926cb2c..2bbdce8 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -754,6 +754,10 @@ ivi_enable_remote_outputs(struct ivi_compositor *ivi)
}
ivi_output = zalloc(sizeof(*ivi_output));
+ if (!ivi_output) {
+ free(_name);
+ continue;
+ }
ivi_output->ivi = ivi;
ivi_output->name = _name;
@@ -806,6 +810,10 @@ ivi_enable_waltham_outputs(struct ivi_compositor *ivi)
}
ivi_output = zalloc(sizeof(*ivi_output));
+ if (!ivi_output) {
+ free(_name);
+ continue;
+ }
ivi_output->ivi = ivi;
ivi_output->name = _name;
diff --git a/src/policy.c b/src/policy.c
index 78994fa..61e0ac2 100644
--- a/src/policy.c
+++ b/src/policy.c
@@ -54,8 +54,14 @@ ivi_policy_state_event_create(uint32_t val, const char *value)
struct state_event *ev_st = zalloc(sizeof(*ev_st));
size_t value_len = strlen(value);
+ if (!ev_st)
+ return NULL;
ev_st->value = val;
ev_st->name = zalloc(sizeof(char) * value_len + 1);
+ if (!ev_st->name) {
+ free(ev_st);
+ return NULL;
+ }
memcpy(ev_st->name, value, value_len);
return ev_st;
@@ -69,6 +75,8 @@ ivi_policy_add_state(struct ivi_policy *policy, uint32_t state, const char *valu
return;
ev_st = ivi_policy_state_event_create(state, value);
+ if (!ev_st)
+ return;
wl_list_insert(&policy->states, &ev_st->link);
}
@@ -80,6 +88,8 @@ ivi_policy_add_event(struct ivi_policy *policy, uint32_t ev, const char *value)
return;
ev_st = ivi_policy_state_event_create(ev, value);
+ if (!ev_st)
+ return;
wl_list_insert(&policy->events, &ev_st->link);
}
@@ -93,6 +103,8 @@ ivi_policy_add_default_states(struct ivi_policy *policy)
for (uint32_t i = 0; i < ARRAY_LENGTH(default_states); i ++) {
struct state_event *ev_st =
ivi_policy_state_event_create(i, default_states[i]);
+ if (!ev_st)
+ return;
wl_list_insert(&policy->states, &ev_st->link);
}
}
@@ -107,6 +119,8 @@ ivi_policy_add_default_events(struct ivi_policy *policy)
for (uint32_t i = 0; i < ARRAY_LENGTH(default_events); i ++) {
struct state_event *ev_st =
ivi_policy_state_event_create(i, default_events[i]);
+ if (!ev_st)
+ return;
wl_list_insert(&policy->events, &ev_st->link);
}
}
@@ -173,6 +187,8 @@ ivi_policy_create(struct ivi_compositor *ivi,
{
struct ivi_policy *policy = zalloc(sizeof(*policy));
+ if (!policy)
+ return NULL;
policy->user_data = user_data;
policy->ivi = ivi;
policy->state_change_in_progress = false;
@@ -270,10 +286,6 @@ ivi_policy_add(struct ivi_policy *policy, const char *app_id, uint32_t state,
return -1;
}
- a_policy = zalloc(sizeof(*a_policy));
- if (!a_policy)
- return -1;
-
if (policy->state_change_in_progress)
return -1;
@@ -286,8 +298,16 @@ ivi_policy_add(struct ivi_policy *policy, const char *app_id, uint32_t state,
if (!ivi_policy_state_is_known(state, policy))
return -1;
+ a_policy = zalloc(sizeof(*a_policy));
+ if (!a_policy)
+ return -1;
+
app_id_len = strlen(app_id);
a_policy->app_id = zalloc(sizeof(char) * app_id_len + 1);
+ if (!a_policy->app_id) {
+ free(a_policy);
+ return -1;
+ }
memcpy(a_policy->app_id, app_id, app_id_len);
a_policy->state = state;
diff --git a/src/shell.c b/src/shell.c
index 0ecdb5e..048cbeb 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -243,7 +243,13 @@ ivi_ensure_popup(struct ivi_output *ioutput, int x, int y, int bx, int by,
struct pending_popup *p_popup = zalloc(sizeof(*p_popup));
size_t len_app_id = strlen(app_id);
+ if (!p_popup)
+ return NULL;
p_popup->app_id = zalloc(sizeof(char) * (len_app_id + 1));
+ if (!p_popup->app_id) {
+ free(p_popup);
+ return NULL;
+ }
memcpy(p_popup->app_id, app_id, len_app_id);
p_popup->ioutput = ioutput;
p_popup->x = x;
@@ -270,6 +276,8 @@ ivi_update_popup(struct ivi_output *ioutput, int x, int y, int bx, int by,
free(p_popup->app_id);
p_popup->app_id = zalloc(sizeof(char) * (len_app_id + 1));
+ if (!p_popup->app_id)
+ return;
memcpy(p_popup->app_id, app_id, len_app_id);
p_popup->ioutput = ioutput;
@@ -288,7 +296,13 @@ ivi_ensure_fullscreen(struct ivi_output *ioutput, const char *app_id)
struct pending_fullscreen *p_fullscreen = zalloc(sizeof(*p_fullscreen));
size_t len_app_id = strlen(app_id);
+ if (!p_fullscreen)
+ return NULL;
p_fullscreen->app_id = zalloc(sizeof(char) * (len_app_id + 1));
+ if (!p_fullscreen->app_id) {
+ free(p_fullscreen);
+ return NULL;
+ }
memcpy(p_fullscreen->app_id, app_id, len_app_id);
p_fullscreen->ioutput = ioutput;
@@ -308,6 +322,8 @@ ivi_update_fullscreen(struct ivi_output *ioutput, const char *app_id,
free(p_fullscreen->app_id);
p_fullscreen->app_id = zalloc(sizeof(char) * (len_app_id + 1));
+ if (!p_fullscreen->app_id)
+ return;
memcpy(p_fullscreen->app_id, app_id, len_app_id);
p_fullscreen->ioutput = ioutput;
@@ -319,7 +335,13 @@ ivi_ensure_remote(struct ivi_output *ioutput, const char *app_id)
struct pending_remote *p_remote = zalloc(sizeof(*p_remote));
size_t len_app_id = strlen(app_id);
+ if (!p_remote)
+ return NULL;
p_remote->app_id = zalloc(sizeof(char) * (len_app_id + 1));
+ if (!p_remote->app_id) {
+ free(p_remote);
+ return NULL;
+ }
memcpy(p_remote->app_id, app_id, len_app_id);
p_remote->ioutput = ioutput;
@@ -339,6 +361,8 @@ ivi_update_remote(struct ivi_output *ioutput, const char *app_id,
free(p_remote->app_id);
p_remote->app_id = zalloc(sizeof(char) * (len_app_id + 1));
+ if (!p_remote->app_id)
+ return;
memcpy(p_remote->app_id, app_id, len_app_id);
p_remote->ioutput = ioutput;
@@ -360,6 +384,8 @@ ivi_set_pending_desktop_surface_popup(struct ivi_output *ioutput, int x, int y,
p_popup = ivi_ensure_popup(ioutput, x, y, bx, by, width, height, app_id);
else
ivi_update_popup(ioutput, x, y, bx, by, width, height, app_id, p_popup);
+ if (!p_popup)
+ return;
wl_list_insert(&ivi->popup_pending_apps, &p_popup->link);
}
@@ -381,6 +407,8 @@ ivi_set_pending_desktop_surface_fullscreen(struct ivi_output *ioutput,
else
ivi_update_fullscreen(ioutput, app_id, p_fullscreen);
+ if (!p_fullscreen)
+ return;
wl_list_insert(&ivi->fullscreen_pending_apps, &p_fullscreen->link);
}
@@ -405,7 +433,13 @@ ivi_set_pending_desktop_surface_split(struct ivi_output *ioutput,
return;
split = zalloc(sizeof(*split));
+ if (!split)
+ return;
split->app_id = zalloc(sizeof(char) * (len_app_id + 1));
+ if (!split->app_id) {
+ free(split);
+ return;
+ }
memcpy(split->app_id, app_id, len_app_id);
split->ioutput = ioutput;
@@ -430,6 +464,8 @@ ivi_set_pending_desktop_surface_remote(struct ivi_output *ioutput,
p_remote = ivi_ensure_remote(ioutput, app_id);
else
ivi_update_remote(ioutput, app_id, p_remote);
+ if (!p_remote)
+ return;
wl_list_insert(&ivi->remote_pending_apps, &remote->link);
}
@@ -849,6 +885,10 @@ create_black_surface_view(struct ivi_output *output)
weston_view_set_position(view, woutput->x, woutput->y);
output->fullscreen_view.fs = zalloc(sizeof(struct ivi_surface));
+ if (!output->fullscreen_view.fs) {
+ weston_surface_destroy(surface);
+ return;
+ }
output->fullscreen_view.fs->view = view;
output->fullscreen_view.fs_destroy.notify = destroy_black_view;