mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-28 03:33:42 +00:00
Refine memory management (#579)
- Added one macro to avoid dangling pointers - Added two functions to perform NULL pointer check since the allocation is not guaranteed by C library, although it is a rare case, just for sanity - Add NULL pointer check to brealloc() and bfree() and for sanity as well Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
This commit is contained in:
+5
-4
@@ -66,6 +66,7 @@
|
||||
#include "json.h"
|
||||
#include "utils.h"
|
||||
#include "manager.h"
|
||||
#include "mm-wrapper.h"
|
||||
|
||||
#ifndef BUF_SIZE
|
||||
#define BUF_SIZE 65535
|
||||
@@ -323,7 +324,7 @@ static void remove_server(char *prefix, char *port)
|
||||
cork_hash_table_delete(server_table, (void *)port, (void **)&old_port, (void **)&old_server);
|
||||
|
||||
if (old_server != NULL) {
|
||||
free(old_server);
|
||||
SS_SAFEFREE(old_server);
|
||||
}
|
||||
|
||||
stop_server(prefix, port);
|
||||
@@ -371,7 +372,7 @@ static void manager_recv_cb(EV_P_ ev_io *w, int revents)
|
||||
if (server == NULL || server->port[0] == 0 || server->password[0] == 0) {
|
||||
LOGE("invalid command: %s:%s", buf, get_data(buf, r));
|
||||
if (server != NULL) {
|
||||
free(server);
|
||||
SS_SAFEFREE(server);
|
||||
}
|
||||
goto ERROR_MSG;
|
||||
}
|
||||
@@ -389,13 +390,13 @@ static void manager_recv_cb(EV_P_ ev_io *w, int revents)
|
||||
if (server == NULL || server->port[0] == 0) {
|
||||
LOGE("invalid command: %s:%s", buf, get_data(buf, r));
|
||||
if (server != NULL) {
|
||||
free(server);
|
||||
SS_SAFEFREE(server);
|
||||
}
|
||||
goto ERROR_MSG;
|
||||
}
|
||||
|
||||
remove_server(working_dir, server->port);
|
||||
free(server);
|
||||
SS_SAFEFREE(server);
|
||||
|
||||
char msg[3] = "ok";
|
||||
if (sendto(manager->fd, msg, 3, 0, (struct sockaddr *)&claddr, len) != 3) {
|
||||
|
||||
Reference in New Issue
Block a user