Mercurial
diff seobeo/s_linux_network.c @ 16:fb2cff495a60
[Seobeo] Fixed the problem with edge server.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Fri, 03 Oct 2025 09:55:51 -0700 |
| parents | 1e61008b9980 |
| children | d97ec3ded2ae |
line wrap: on
line diff
--- a/seobeo/s_linux_network.c Fri Oct 03 06:50:33 2025 -0700 +++ b/seobeo/s_linux_network.c Fri Oct 03 09:55:51 2025 -0700 @@ -106,6 +106,7 @@ p_handle->file = NULL; p_handle->text_copy = NULL; p_handle->file_name = NULL; + p_handle->destroyed = false; return p_handle; } @@ -147,14 +148,23 @@ void Seobeo_Handle_Destroy(Seobeo_PHandle p_handle) { - close(p_handle->socket); - free(p_handle->host); - free(p_handle->port); - free(p_handle->read_buffer); - free(p_handle->write_buffer); - free(p_handle->file); - free(p_handle->text_copy); - free(p_handle->file_name); + if (!p_handle) return; + + bool expected = false; + if (!atomic_compare_exchange_strong(&p_handle->destroyed, &expected, true)) + { + // Already destroyed by another thread + return; + } + + if (p_handle->host) free(p_handle->host); + if (p_handle->port) free(p_handle->port); + if (p_handle->socket) close(p_handle->socket); + if (p_handle->read_buffer) free(p_handle->read_buffer); + if (p_handle->write_buffer) free(p_handle->write_buffer); + if (p_handle->text_copy) free(p_handle->text_copy); + if (p_handle->file_name) free(p_handle->file_name); + free(p_handle); }