server: move memset after check

If the malloc fails, memset would touch invalid memory.

Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
This commit is contained in:
Marek Chalupa 2014-08-06 11:28:34 +02:00 committed by Pekka Paalanen
parent e2c0d47b0c
commit a92efe9ad6

View File

@ -1141,10 +1141,11 @@ wl_display_add_socket_auto(struct wl_display *display)
const int MAX_DISPLAYNO = 32;
s = malloc(sizeof *s);
memset(s, 0, sizeof *s);
if (s == NULL)
return NULL;
memset(s, 0, sizeof *s);
do {
snprintf(display_name, sizeof display_name, "wayland-%d", displayno);
if (wl_socket_init_for_display_name(s, display_name) < 0) {