mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-16 00:00:07 +01:00
Subject: [PATCH] Introduce lws_free2() helper to free and re-NULL pointers
Signed-off-by: Alejandro Mery <amery@geeks.cl>
This commit is contained in:
parent
6ff28248aa
commit
ac3ec39bb1
7 changed files with 17 additions and 36 deletions
|
@ -781,8 +781,7 @@ check_accept:
|
|||
return 0;
|
||||
|
||||
bail3:
|
||||
lws_free(wsi->u.ws.rx_user_buffer);
|
||||
wsi->u.ws.rx_user_buffer = NULL;
|
||||
lws_free2(wsi->u.ws.rx_user_buffer);
|
||||
close_reason = LWS_CLOSE_STATUS_NOSTATUS;
|
||||
|
||||
bail2:
|
||||
|
|
|
@ -76,8 +76,7 @@ static void lws_daemon_closing(int sigact)
|
|||
if (getpid() == pid_daemon)
|
||||
if (lock_path) {
|
||||
unlink(lock_path);
|
||||
lws_free(lock_path);
|
||||
lock_path = NULL;
|
||||
lws_free2(lock_path);
|
||||
}
|
||||
|
||||
kill(getpid(), SIGKILL);
|
||||
|
|
|
@ -208,35 +208,26 @@ just_kill_connection:
|
|||
remove_wsi_socket_from_fds(context, wsi);
|
||||
|
||||
wsi->state = WSI_STATE_DEAD_SOCKET;
|
||||
|
||||
if (wsi->rxflow_buffer) {
|
||||
lws_free(wsi->rxflow_buffer);
|
||||
wsi->rxflow_buffer = NULL;
|
||||
}
|
||||
|
||||
lws_free2(wsi->rxflow_buffer);
|
||||
|
||||
if (wsi->mode == LWS_CONNMODE_HTTP2_SERVING && wsi->u.hdr.ah) {
|
||||
lws_free(wsi->u.hdr.ah);
|
||||
wsi->u.hdr.ah = NULL;
|
||||
lws_free2(wsi->u.hdr.ah);
|
||||
}
|
||||
|
||||
|
||||
if ((old_state == WSI_STATE_ESTABLISHED ||
|
||||
wsi->mode == LWS_CONNMODE_WS_SERVING ||
|
||||
wsi->mode == LWS_CONNMODE_WS_CLIENT)) {
|
||||
|
||||
if (wsi->u.ws.rx_user_buffer) {
|
||||
lws_free(wsi->u.ws.rx_user_buffer);
|
||||
wsi->u.ws.rx_user_buffer = NULL;
|
||||
}
|
||||
lws_free2(wsi->u.ws.rx_user_buffer);
|
||||
|
||||
if (wsi->truncated_send_malloc) {
|
||||
/* not going to be completed... nuke it */
|
||||
lws_free(wsi->truncated_send_malloc);
|
||||
wsi->truncated_send_malloc = NULL;
|
||||
lws_free2(wsi->truncated_send_malloc);
|
||||
wsi->truncated_send_len = 0;
|
||||
}
|
||||
if (wsi->u.ws.ping_payload_buf) {
|
||||
lws_free(wsi->u.ws.ping_payload_buf);
|
||||
wsi->u.ws.ping_payload_buf = NULL;
|
||||
lws_free2(wsi->u.ws.ping_payload_buf);
|
||||
wsi->u.ws.ping_payload_alloc = 0;
|
||||
wsi->u.ws.ping_payload_len = 0;
|
||||
}
|
||||
|
|
|
@ -77,10 +77,8 @@ int lws_allocate_header_table(struct libwebsocket *wsi)
|
|||
|
||||
int lws_free_header_table(struct libwebsocket *wsi)
|
||||
{
|
||||
if (wsi->u.hdr.ah) {
|
||||
lws_free(wsi->u.hdr.ah);
|
||||
wsi->u.hdr.ah = NULL;
|
||||
}
|
||||
lws_free2(wsi->u.hdr.ah);
|
||||
wsi->u.hdr.ah = NULL;
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
@ -894,8 +892,7 @@ spill:
|
|||
/* if existing buffer is too small, drop it */
|
||||
if (wsi->u.ws.ping_payload_buf &&
|
||||
wsi->u.ws.ping_payload_alloc < wsi->u.ws.rx_user_buffer_head) {
|
||||
lws_free(wsi->u.ws.ping_payload_buf);
|
||||
wsi->u.ws.ping_payload_buf = NULL;
|
||||
lws_free2(wsi->u.ws.ping_payload_buf);
|
||||
}
|
||||
|
||||
/* if no buffer, allocate it */
|
||||
|
|
|
@ -1168,6 +1168,7 @@ lws_zalloc(size_t size);
|
|||
|
||||
#define lws_malloc(S) lws_realloc(NULL, S)
|
||||
#define lws_free(P) lws_realloc(P, 0)
|
||||
#define lws_free2(P) do { lws_realloc(P, 0); (P) = NULL; } while(0)
|
||||
|
||||
/*
|
||||
* lws_plat_
|
||||
|
|
11
lib/server.c
11
lib/server.c
|
@ -295,9 +295,7 @@ got_uri:
|
|||
}
|
||||
|
||||
/* now drop the header info we kept a pointer to */
|
||||
lws_free(wsi->u.http.ah);
|
||||
/* not possible to continue to use past here */
|
||||
wsi->u.http.ah = NULL;
|
||||
lws_free2(wsi->u.http.ah);
|
||||
|
||||
if (n) {
|
||||
lwsl_info("LWS_CALLBACK_HTTP closing\n");
|
||||
|
@ -320,11 +318,8 @@ got_uri:
|
|||
|
||||
bail_nuke_ah:
|
||||
/* drop the header info */
|
||||
if (wsi->u.hdr.ah) {
|
||||
lws_free(wsi->u.hdr.ah);
|
||||
wsi->u.hdr.ah = NULL;
|
||||
}
|
||||
|
||||
lws_free2(wsi->u.hdr.ah);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
@ -564,8 +564,7 @@ drain:
|
|||
if (draining_flow && wsi->rxflow_buffer &&
|
||||
wsi->rxflow_pos == wsi->rxflow_len) {
|
||||
lwsl_info("flow buffer: drained\n");
|
||||
lws_free(wsi->rxflow_buffer);
|
||||
wsi->rxflow_buffer = NULL;
|
||||
lws_free2(wsi->rxflow_buffer);
|
||||
/* having drained the rxflow buffer, can rearm POLLIN */
|
||||
_libwebsocket_rx_flow_control(wsi); /* n ignored, needed for NO_SERVER case */
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue