01_SDK/nimble/host/nimble/nimble/host/src/ble_gatts.c
@@ -1155,7 +1155,7 @@
static void
ble_gatts_free_svc_defs(void)
{
    free(ble_gatts_svc_defs);
    nimble_mem_free(ble_gatts_svc_defs);
    ble_gatts_svc_defs = NULL;
    ble_gatts_num_svc_defs = 0;
}
@@ -1163,10 +1163,10 @@
static void
ble_gatts_free_mem(void)
{
    free(ble_gatts_clt_cfg_mem);
    nimble_mem_free(ble_gatts_clt_cfg_mem);
    ble_gatts_clt_cfg_mem = NULL;
    free(ble_gatts_svc_entries);
    nimble_mem_free(ble_gatts_svc_entries);
    ble_gatts_svc_entries = NULL;
}
@@ -1196,7 +1196,7 @@
    }
    if (ble_hs_max_client_configs > 0) {
        ble_gatts_clt_cfg_mem = pvPortMalloc(
        ble_gatts_clt_cfg_mem = nimble_mem_alloc(
            OS_MEMPOOL_BYTES(ble_hs_max_client_configs,
                             sizeof (struct ble_gatts_clt_cfg)));
        if (ble_gatts_clt_cfg_mem == NULL) {
@@ -1207,7 +1207,7 @@
    if (ble_hs_max_services > 0) {
        ble_gatts_svc_entries =
            pvPortMalloc(ble_hs_max_services * sizeof *ble_gatts_svc_entries);
            nimble_mem_alloc(ble_hs_max_services * sizeof *ble_gatts_svc_entries);
        if (ble_gatts_svc_entries == NULL) {
            rc = BLE_HS_ENOMEM;
            goto done;
@@ -1962,12 +1962,24 @@
        goto done;
    }
#if 1
   p = nimble_mem_alloc((ble_gatts_num_svc_defs + 1) * sizeof *ble_gatts_svc_defs);
    if (p == NULL) {
        rc = BLE_HS_ENOMEM;
        goto done;
    }
    memcpy(p, ble_gatts_svc_defs, ble_gatts_num_svc_defs * (sizeof *ble_gatts_svc_defs));
    nimble_mem_free(ble_gatts_svc_defs);
#else
    p = realloc(ble_gatts_svc_defs,
                (ble_gatts_num_svc_defs + 1) * sizeof *ble_gatts_svc_defs);
    if (p == NULL) {
        rc = BLE_HS_ENOMEM;
        goto done;
    }
#endif
    ble_gatts_svc_defs = p;
    ble_gatts_svc_defs[ble_gatts_num_svc_defs] = svcs;