static bool set_wake_alarm_cb(uint64_t delay_millis, bool should_wake, alarm_cb cb, void* data) { struct wake_alarm_param* param; param = malloc(sizeof(*param)); if (!param) { ALOGE_ERRNO("malloc"); return false; } memset(¶m->evfuncs, 0, sizeof(param->evfuncs)); param->evfuncs.data = param; param->evfuncs.epollin = alarm_event_in; param->clockid = should_wake ? CLOCK_BOOTTIME_ALARM : CLOCK_BOOTTIME; param->timeout_ms = delay_millis; param->interval_ms = 0; param->cb = cb; param->data = data; if (run_task(set_wake_alarm_task_cb, param) < 0) goto err_run_task; return true; err_run_task: free(param); return false; }
static struct get_remote_service_record_params* alloc_get_remote_service_record_params(void) { struct get_remote_service_record_params* params; params = malloc(sizeof(*params)); if (!params){ ALOGE_ERRNO("malloc"); return NULL; } return params; }
static bt_status_t opcode_get_element_attr_rsp(const struct pdu* cmd) { long off; uint8_t num_attr; btrc_element_attr_val_t* p_attrs; struct pdu_wbuf* wbuf; bt_status_t status; assert(btrc_interface); assert(btrc_interface->get_element_attr_rsp); off = read_pdu_at(cmd, 0, "C", &num_attr); if (off < 0) return BT_STATUS_PARM_INVALID; p_attrs = malloc(num_attr * sizeof(*p_attrs)); if (!p_attrs) { ALOGE_ERRNO("malloc"); return BT_STATUS_NOMEM; } off = read_btrc_element_attr_val_t_array(cmd, off, p_attrs, num_attr); if (off < 0) { status = BT_STATUS_PARM_INVALID; goto err_read_btrc_element_attr_val_t_array; } wbuf = create_pdu_wbuf(0, 0, NULL); if (!wbuf) { status = BT_STATUS_NOMEM; goto err_create_pdu_wbuf; } status = btrc_interface->get_element_attr_rsp(num_attr, p_attrs); if (status != BT_STATUS_SUCCESS) goto err_btrc_interface_get_element_attr_rsp; init_pdu(&wbuf->buf.pdu, cmd->service, cmd->opcode); send_pdu(wbuf); free(p_attrs); return BT_STATUS_SUCCESS; err_btrc_interface_get_element_attr_rsp: cleanup_pdu_wbuf(wbuf); err_create_pdu_wbuf: err_read_btrc_element_attr_val_t_array: free(p_attrs); return status; }
/* See Bug 989976: consider address in |properties| is not aligned. If * it is aligned, we return the pointer directly; otherwise we make * an aligned copy. The argument |aligned_properties| keeps track of * the memory buffer. */ static bt_property_t* align_properties(bt_property_t* properties, size_t num_properties, bt_property_t** aligned_properties) { size_t siz; if (is_aligned(properties)) { *aligned_properties = NULL; return properties; } siz = sizeof(**aligned_properties) * num_properties; *aligned_properties = malloc(siz); if (!*aligned_properties) { ALOGE_ERRNO("malloc"); return NULL; } memcpy(*aligned_properties, properties, siz); return *aligned_properties; }