void handle_deinit(void) { status_bar_deinit(); // Always have 40B memory leak due to tick_timer_service_subscribe() #ifdef PBL_ROUND round_bottom_bar_deinit(); #endif favorites_deinit(); stations_deinit(); locale_deinit(); settings_deinit(); message_deinit(); // Always have 16B memory leak due to app_message_set_context() }
static void destroy_ui(void) { window_destroy(s_window); text_layer_destroy(s_time_hr); text_layer_destroy(s_time_hr2); text_layer_destroy(s_time_min); text_layer_destroy(s_time_min2); text_layer_destroy(s_weather_temp); text_layer_destroy(s_date_year); text_layer_destroy(s_date_year2); text_layer_destroy(s_date_day); text_layer_destroy(s_date_month); //text_layer_destroy(s_day_h); //text_layer_destroy(s_month_h); text_layer_destroy(s_day_v); text_layer_destroy(s_date_day_v); text_layer_destroy(s_month_v); text_layer_destroy(s_year_v); text_layer_destroy(s_ampm); text_layer_destroy(s_battery); fonts_unload_custom_font(s_res_sqr_num); fonts_unload_custom_font(s_res_sqr_num_32); fonts_unload_custom_font(s_res_scp); fonts_unload_custom_font(s_res_scp_20); bitmap_layer_destroy(s_weather_image); bitmap_layer_destroy(s_bluetooth_image); gbitmap_destroy(s_res_w01d); gbitmap_destroy(s_res_w01n); gbitmap_destroy(s_res_w02d); gbitmap_destroy(s_res_w02n); gbitmap_destroy(s_res_w03d); gbitmap_destroy(s_res_w04d); gbitmap_destroy(s_res_w09d); gbitmap_destroy(s_res_w10d); gbitmap_destroy(s_res_w10n); gbitmap_destroy(s_res_w11d); gbitmap_destroy(s_res_w13d); gbitmap_destroy(s_res_w50d); gbitmap_destroy(s_res_bluetooth); gbitmap_destroy(s_res_bluetoothOff); free(s_colors); message_deinit(); // stop weather services }
static void process_frames(wiced_tcp_socket_t *sock, websocket_msg_handler_t binary_msg_handler, websocket_msg_handler_t text_msg_handler, void *ctx) { wiced_result_t ret; char *buf, *cur; uint32_t len; websocket_frame_t frame; websocket_message_t msg; wiced_bool_t exit_loop = WICED_FALSE; message_init(&msg); while (WICED_TRUE) { buf = NULL; ret = receive_data(sock, 3000, &buf, &len); if (ret == WICED_TIMEOUT) { continue; } if (ret != WICED_SUCCESS) { WPRINT_LIB_INFO( ("(WebSocket) Failed to read from socket (err=%u)\n", ret) ); break; } WPRINT_LIB_DEBUG( ("(WebSocket) Received %u bytes\n", (unsigned int)len) ); cur = buf; while (len > 0) { if (get_frame(&cur, &len, &frame) != WICED_SUCCESS) { WPRINT_LIB_INFO( ("(WebSocket) Failed to read frame (err=%u)\n", ret) ); exit_loop = WICED_TRUE; break; } if (frame.opcode == WS_OPCODE_PING) { WPRINT_LIB_DEBUG( ("(WebSocket) Received PING frame.\n")); send_control_frame(sock, WS_OPCODE_PONG, frame.payload, frame.payload_len); } else if (frame.opcode == WS_OPCODE_PONG) { WPRINT_LIB_DEBUG( ("(WebSocket) Received PONG frame.\n")); /* Nothing to do. */ } else if (frame.opcode == WS_OPCODE_CLOSE) { WPRINT_LIB_DEBUG( ("(WebSocket) Received CLOSE frame.\n") ); /* Echo the CLOSE frame with the 2-byte status code. */ if (frame.payload_len >= 2) { send_control_frame(sock, WS_OPCODE_CLOSE, frame.payload, 2); } else { send_control_frame(sock, WS_OPCODE_CLOSE, NULL, 0); } exit_loop = WICED_TRUE; break; } else if (frame.opcode == WS_OPCODE_CONTINUATION) { WPRINT_LIB_DEBUG( ("(WebSocket) Received CONTINUATION frame.\n") ); if (msg.is_active) { message_append(&msg, frame.payload, frame.payload_len); if (frame.is_final) { consume_message(&msg, binary_msg_handler, text_msg_handler, ctx); } } else { exit_loop = WICED_TRUE; break; } } else if (frame.opcode == WS_OPCODE_TEXT) { WPRINT_LIB_DEBUG( ("(WebSocket) Received TEXT frame.\n") ); if (msg.is_active) { WPRINT_LIB_DEBUG( ("(WebSocket) A pending message already exists.\n") ); exit_loop = WICED_TRUE; break; } message_start(&msg, WICED_TRUE, frame.payload, frame.payload_len); if (frame.is_final) { consume_message(&msg, binary_msg_handler, text_msg_handler, ctx); } } else if (frame.opcode == WS_OPCODE_BINARY) { WPRINT_LIB_DEBUG( ("(WebSocket) Received BINARY frame.\n") ); if (msg.is_active) { WPRINT_LIB_DEBUG( ("(WebSocket) A pending message already exists.\n") ); exit_loop = WICED_TRUE; break; } message_start(&msg, WICED_FALSE, frame.payload, frame.payload_len); if (frame.is_final) { consume_message(&msg, binary_msg_handler, text_msg_handler, ctx); } } else { WPRINT_LIB_INFO(("(WebSocket) Received invalid opcode %02X\n", frame.opcode)); exit_loop = WICED_TRUE; break; } } free(buf); if (exit_loop) { WPRINT_LIB_INFO( ("(WebSocket) Exiting read loop.\n") ); break; } } message_deinit(&msg); }