From c77e7c454e8be9a41db66d4354139de66b40ff0c Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 23 Nov 2018 18:02:27 +0100 Subject: [PATCH] initialze other malloc'ed memory --- platform/corefoundation/btstack_run_loop_corefoundation.m | 1 + platform/daemon/src/daemon.c | 2 ++ platform/daemon/src/rfcomm_service_db_memory.c | 1 + platform/libusb/hci_transport_h2_libusb.c | 1 + platform/posix/btstack_tlv_posix.c | 4 +++- 5 files changed, 8 insertions(+), 1 deletion(-) diff --git a/platform/corefoundation/btstack_run_loop_corefoundation.m b/platform/corefoundation/btstack_run_loop_corefoundation.m index c0e4afcc6..2d545609a 100644 --- a/platform/corefoundation/btstack_run_loop_corefoundation.m +++ b/platform/corefoundation/btstack_run_loop_corefoundation.m @@ -133,6 +133,7 @@ static void btstack_run_loop_corefoundation_add_data_source(btstack_data_source_ CFRunLoopSourceRef socket_run_loop = CFSocketCreateRunLoopSource ( kCFAllocatorDefault, socket, 0); // store CFSocketRef and CFRunLoopSource in struct on heap + memset(references, 0, sizeof(btstack_corefoundation_data_source_helper_t)); references->socket = socket; references->socket_run_loop = socket_run_loop; diff --git a/platform/daemon/src/daemon.c b/platform/daemon/src/daemon.c index 2102e9c52..1e8cb90dc 100644 --- a/platform/daemon/src/daemon.c +++ b/platform/daemon/src/daemon.c @@ -282,6 +282,7 @@ static void add_uint32_to_list(btstack_linked_list_t *list, uint32_t value){ btstack_linked_list_uint32_t * item = malloc(sizeof(btstack_linked_list_uint32_t)); if (!item) return; + memset(item, 0, sizeof(btstack_linked_list_uint32_t)); item->value = value; btstack_linked_list_add(list, (btstack_linked_item_t *) item); } @@ -1311,6 +1312,7 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui // start listening btstack_linked_list_gatt_client_notification_t * linked_notification = malloc(sizeof(btstack_linked_list_gatt_client_notification_t)); if (!linked_notification) break; + memset(linked_notification, 0, sizeof(btstack_linked_list_gatt_client_notification_t)); log_info("Start gatt notification listener %p", linked_notification); gatt_client_listen_for_characteristic_value_updates(&linked_notification->notification_listener, &handle_gatt_client_event, gatt_helper->con_handle, &characteristic); btstack_linked_list_add(&gatt_helper->gatt_client_notifications, (btstack_linked_item_t *) linked_notification); diff --git a/platform/daemon/src/rfcomm_service_db_memory.c b/platform/daemon/src/rfcomm_service_db_memory.c index 3af401497..c8b48e47e 100644 --- a/platform/daemon/src/rfcomm_service_db_memory.c +++ b/platform/daemon/src/rfcomm_service_db_memory.c @@ -78,6 +78,7 @@ uint8_t rfcomm_service_db_channel_for_service(const char *serviceName){ if (!newItem) return 0; + memset(new, 0, sizeof(db_mem_service_t)); strncpy(newItem->service_name, serviceName, MAX_NAME_LEN); newItem->service_name[MAX_NAME_LEN] = 0; newItem->channel = max_channel; diff --git a/platform/libusb/hci_transport_h2_libusb.c b/platform/libusb/hci_transport_h2_libusb.c index 285ce857e..69b369401 100644 --- a/platform/libusb/hci_transport_h2_libusb.c +++ b/platform/libusb/hci_transport_h2_libusb.c @@ -1100,6 +1100,7 @@ static int usb_open(void){ usb_close(); return 1; } + memset(pollfd_data_sources, 0, sizeof(btstack_data_source_t) * num_pollfds); for (r = 0 ; r < num_pollfds ; r++) { btstack_data_source_t *ds = &pollfd_data_sources[r]; btstack_run_loop_set_data_source_fd(ds, pollfd[r]->fd); diff --git a/platform/posix/btstack_tlv_posix.c b/platform/posix/btstack_tlv_posix.c index eabd5e9ff..2aa3ec57e 100644 --- a/platform/posix/btstack_tlv_posix.c +++ b/platform/posix/btstack_tlv_posix.c @@ -146,8 +146,10 @@ static int btstack_tlv_posix_store_tag(void * context, uint32_t tag, const uint8 } // create new entry - tlv_entry_t * new_entry = (tlv_entry_t *) malloc(sizeof(tlv_entry_t) - DUMMY_SIZE + data_size); + uint32_t entry_size = sizeof(tlv_entry_t) - DUMMY_SIZE + data_size; + tlv_entry_t * new_entry = (tlv_entry_t *) malloc(entry_size); if (!new_entry) return 0; + memset(new_entry, 0, entry_size); new_entry->tag = tag; new_entry->len = data_size; memcpy(&new_entry->value[0], data, data_size);