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

[linux] Fix seg fault error if we do network provisioning twice. #4770

Merged
merged 1 commit into from
Feb 10, 2021
Merged

[linux] Fix seg fault error if we do network provisioning twice. #4770

merged 1 commit into from
Feb 10, 2021

Conversation

yufengwangca
Copy link
Contributor

Problem

The linux device crashed if we do network provisioning twice:
chip::DeviceLayer::ConnectivityMgrImpl().StartWiFiManagement();
(wait)
chip::DeviceLayer::ConnectivityManagerImpl::ProvisionWiFiNetwork(ssid, passwd);
(wait)
chip::DeviceLayer::ConnectivityManagerImpl::ProvisionWiFiNetwork(ssid, passwd);

According to the backtrace, seems we have some kind of double free issue:

#0 0x0000fffff7a3000c in g_type_check_instance_is_fundamentally_a () at /lib/aarch64-linux-gnu/libgobject-2.0.so.0
#1 0x0000fffff7a139b8 in g_object_unref () at /lib/aarch64-linux-gnu/libgobject-2.0.so.0
#2 0x0000aaaaaaae46a4 in chip::DeviceLayer::ConnectivityManagerImpl::ProvisionWiFiNetwork(char const*, char const*)
(this=0xaaaaaab919b8 chip::DeviceLayer::ConnectivityManagerImpl::sInstance, ssid=0xffffffffe7d0 "Nest-T", key=0xffffffffe7f8 "Nesttesting")
at ../third_party/connectedhomeip/src/platform/Linux/ConnectivityManagerImpl.cpp:849

Summary of Changes

Clean up current network if exists before provisioning

Fixes #4269


// Clean up current network if exists
if (mWpaSupplicant.networkPath)
{
g_object_unref(mWpaSupplicant.networkPath);
mWpaSupplicant.networkPath = nullptr;
GError * error = nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't you use err here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if result == true and error is not null (which is highly unlikely), This temporary variable 'error' needs to be freed after use. So I prefer not reuse err in the outer space for local error handling.

@woody-apple woody-apple merged commit 2c22ad9 into project-chip:master Feb 10, 2021
@yufengwangca yufengwangca deleted the pr/linux/wifi branch February 10, 2021 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The linux device crashed if we do network provisioning twice
5 participants