Skip to content

Conversation

@Synss
Copy link
Contributor

@Synss Synss commented May 20, 2021

This fixes a warning in clang tidy:

Call to virtual method 'ClientImpl::shutdown_ssl' during
destruction bypasses virtual dispatch

ClientImpl::~ClientImpl() calls lock_socket_and_shutdown_and_close()
that itself calls shutdown_ssl(). However, shutdown_ssl() is virtual
and C++ does not perform virtual dispatch in destructors, which results
in the wrong overload being called.

This change adds a non-virtual shutdown_ssl_impl() function that is
called from ~SSLClient(). We also inline sock_socket_and_shutdown_and_close()
and removes the virtual call in ~ClientImpl().

@Synss
Copy link
Contributor Author

Synss commented May 20, 2021

With this patch, you might as well inline and remove lock_socket_and_shutdown_and_close(), which now has but a single caller. I can do that myself if you like.

@yhirose
Copy link
Owner

yhirose commented May 20, 2021

@Synss, thank you for the improvement.

@lightvector, could you review this change when you have time, since lock_socket_and_shutdown_and_close() came from this patch. Thanks!
02d3cd5

@yhirose
Copy link
Owner

yhirose commented May 22, 2021

@Synss, could you go ahead to inline and remove lock_socket_and_shutdown_and_close?

Synss added 2 commits May 22, 2021 16:04
This fixes a warning in clang tidy:

> Call to virtual method 'ClientImpl::shutdown_ssl' during
> destruction bypasses virtual dispatch

ClientImpl::~ClientImpl() calls lock_socket_and_shutdown_and_close()
that itself calls shutdown_ssl().  However, shutdown_ssl() is virtual
and C++ does not perform virtual dispatch in destructors, which results
in the wrong overload being called.

This change adds a non-virtual shutdown_ssl_impl() function that is
called from ~SSLClient().  We also inline sock_socket_and_shutdown_and_close()
and removes the virtual call in ~ClientImpl().
@Synss Synss force-pushed the fix-virtual-call-in-ctor branch from 1082457 to eef3385 Compare May 22, 2021 14:05
@Synss
Copy link
Contributor Author

Synss commented May 22, 2021

@Synss, could you go ahead to inline and remove lock_socket_and_shutdown_and_close?

Done. I have added eef3385 to this PR.

@yhirose yhirose merged commit 089b9da into yhirose:master May 23, 2021
@yhirose
Copy link
Owner

yhirose commented May 23, 2021

@Synss, thanks for the fine contribution!

ExclusiveOrange pushed a commit to ExclusiveOrange/cpp-httplib-exor that referenced this pull request May 2, 2023
* Fix virtual call in ClientImpl::~ClientImpl()

This fixes a warning in clang tidy:

> Call to virtual method 'ClientImpl::shutdown_ssl' during
> destruction bypasses virtual dispatch

ClientImpl::~ClientImpl() calls lock_socket_and_shutdown_and_close()
that itself calls shutdown_ssl().  However, shutdown_ssl() is virtual
and C++ does not perform virtual dispatch in destructors, which results
in the wrong overload being called.

This change adds a non-virtual shutdown_ssl_impl() function that is
called from ~SSLClient().  We also inline sock_socket_and_shutdown_and_close()
and removes the virtual call in ~ClientImpl().

* Inline and remove lock_socket_and_shutdown_and_close()

The function only has one caller.
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

Successfully merging this pull request may close these issues.

2 participants