Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"void *priv" of "esp_now_peer_info" struct does not seem to work in ESPNOW #28

Open
MrTC1277 opened this issue May 6, 2022 · 0 comments

Comments

@MrTC1277
Copy link

MrTC1277 commented May 6, 2022

I use ESP-IDF, its version is ESP-IDF v5.0-dev-2332-ge498209ed2-dirty
I try to assign a value to "peer->priv" in the following way

esp_now_peer_info_t *peer = malloc(sizeof(esp_now_peer_info_t));
if (peer == NULL)
{
ESP_LOGE(TAG, "Malloc peer information fail");
esp_restart();
}
memset(peer, 0, sizeof(esp_now_peer_info_t));
peer->channel = CONFIG_ESPNOW_CHANNEL;
peer->ifidx = ESPNOW_WIFI_IF;
peer->encrypt = true;
peer_data.heartbeat=111;
peer_data.identity = 4;
peer->priv=malloc(sizeof(espnow_peer_data_t));
memcpy(peer->priv,&peer_data,sizeof(espnow_peer_data_t));
memcpy(peer->lmk, CONFIG_ESPNOW_LMK, ESP_NOW_KEY_LEN);
memcpy(peer->peer_addr, recv_cb.mac_addr, ESP_NOW_ETH_ALEN);
ESP_ERROR_CHECK(esp_now_add_peer(peer));

the “espnow_peer_data_t” is my custom structure

typedef struct 
{
    uint8_t identity;
    uint32_t heartbeat;
}espnow_peer_data_t;

I read the variables in the following way

esp_now_peer_info_t *peer_info;
espnow_peer_data_t *peer_data_point;

peer_info = malloc(sizeof(esp_now_peer_info_t));
esp_now_fetch_peer(true,peer_info);
peer_data_point = (espnow_peer_data_t *)peer_info->priv;
free(peer_info->priv);

The read value is incorrect and caused a restart due to the release of an incorrect memory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant