Index: uspace/srv/hid/remcons/remcons.c
===================================================================
--- uspace/srv/hid/remcons/remcons.c	(revision 513237966a1ea4b66980df2deb5b151213666dae)
+++ uspace/srv/hid/remcons/remcons.c	(revision 47d060dc4e7035ebfea2fa54953c74fd8e0f402a)
@@ -144,4 +144,10 @@
 };
 
+static void remcons_telnet_ws_update(void *, unsigned, unsigned);
+
+static telnet_cb_t remcons_telnet_cb = {
+	.ws_update = remcons_telnet_ws_update
+};
+
 static loc_srv_t *remcons_srv;
 static bool no_ctl;
@@ -260,6 +266,6 @@
 
 	if (remcons->enable_ctl) {
-		*cols = 80;
-		*rows = 25;
+		*cols = remcons->vt->cols;
+		*rows = remcons->vt->rows;
 	} else {
 		*cols = 100;
@@ -352,11 +358,31 @@
 {
 	remcons_event_t *event = malloc(sizeof(remcons_event_t));
-	assert(event);
+	if (event == NULL) {
+		fprintf(stderr, "Out of memory.\n");
+		return NULL;
+	}
 
 	link_initialize(&event->link);
-	event->kbd.type = type;
-	event->kbd.mods = mods;
-	event->kbd.key = key;
-	event->kbd.c = c;
+	event->cev.type = CEV_KEY;
+	event->cev.ev.key.type = type;
+	event->cev.ev.key.mods = mods;
+	event->cev.ev.key.key = key;
+	event->cev.ev.key.c = c;
+
+	return event;
+}
+
+/** Creates new console resize event.
+ */
+static remcons_event_t *new_resize_event(void)
+{
+	remcons_event_t *event = malloc(sizeof(remcons_event_t));
+	if (event == NULL) {
+		fprintf(stderr, "Out of memory.\n");
+		return NULL;
+	}
+
+	link_initialize(&event->link);
+	event->cev.type = CEV_RESIZE;
 
 	return event;
@@ -385,7 +411,5 @@
 	remcons_event_t *tmp = list_get_instance(link, remcons_event_t, link);
 
-	event->type = CEV_KEY;
-	event->ev.key = tmp->kbd;
-
+	*event = tmp->cev;
 	free(tmp);
 
@@ -590,9 +614,35 @@
 
 	remcons_event_t *down = new_kbd_event(KEY_PRESS, mods, key, c);
+	if (down == NULL)
+		return;
+
 	remcons_event_t *up = new_kbd_event(KEY_RELEASE, mods, key, c);
-	assert(down);
-	assert(up);
+	if (up == NULL) {
+		free(down);
+		return;
+	}
+
 	list_append(&down->link, &remcons->in_events);
 	list_append(&up->link, &remcons->in_events);
+}
+
+/** Window size update callback.
+ *
+ * @param arg Argument (remcons_t *)
+ * @param cols New number of columns
+ * @param rows New number of rows
+ */
+static void remcons_telnet_ws_update(void *arg, unsigned cols, unsigned rows)
+{
+	remcons_t *remcons = (remcons_t *)arg;
+
+	vt100_resize(remcons->vt, cols, rows);
+	telnet_user_resize(remcons->user, cols, rows);
+
+	remcons_event_t *resize = new_resize_event();
+	if (resize == NULL)
+		return;
+
+	list_append(&resize->link, &remcons->in_events);
 }
 
@@ -605,8 +655,19 @@
 {
 	char_attrs_t attrs;
-	remcons_t *remcons = calloc(1, sizeof(remcons_t));
-	assert(remcons != NULL); // XXX
-	telnet_user_t *user = telnet_user_create(conn);
-	assert(user);
+	remcons_t *remcons = NULL;
+	telnet_user_t *user = NULL;
+
+	remcons = calloc(1, sizeof(remcons_t));
+	if (remcons == NULL) {
+		fprintf(stderr, "Out of memory.\n");
+		goto error;
+	}
+
+	user = telnet_user_create(conn, &remcons_telnet_cb,
+	    (void *)remcons);
+	if (user == NULL) {
+		fprintf(stderr, "Out of memory.\n");
+		goto error;
+	}
 
 	remcons->enable_ctl = !no_ctl;
@@ -626,5 +687,9 @@
 
 	remcons->vt = vt100_create((void *)remcons, 80, 25, &remcons_vt_cb);
-	assert(remcons->vt != NULL); // XXX
+	if (remcons->vt == NULL) {
+		fprintf(stderr, "Error creating VT100 driver instance.\n");
+		goto error;
+	}
+
 	remcons->vt->enable_rgb = remcons->enable_rgb;
 
@@ -649,5 +714,5 @@
 		telnet_user_error(user, "Unable to register %s with loc: %s.",
 		    user->service_name, str_error(rc));
-		return;
+		goto error;
 	}
 
@@ -656,5 +721,8 @@
 
 	fid_t spawn_fibril = fibril_create(spawn_task_fibril, user);
-	assert(spawn_fibril);
+	if (spawn_fibril == 0) {
+		fprintf(stderr, "Failed creating fibril.\n");
+		goto error;
+	}
 	fibril_add_ready(spawn_fibril);
 
@@ -685,4 +753,14 @@
 	telnet_user_log(user, "Destroying...");
 	telnet_user_destroy(user);
+	return;
+error:
+	if (user != NULL && user->service_id != 0)
+		loc_service_unregister(remcons_srv, user->service_id);
+	if (user != NULL)
+		free(user);
+	if (remcons != NULL && remcons->vt != NULL)
+		vt100_destroy(remcons->vt);
+	if (remcons != NULL)
+		free(remcons);
 }
 
