Browse Source

build: add --asan flag to build.sh, tcp_io: null sock/queues in destroy + guard read_cb/write_cb

chatgui
Evgeny 3 months ago
parent
commit
4716e54069
  1. 26
      build.sh
  2. 10
      lib/tcp_io.c

26
build.sh

@ -5,6 +5,7 @@
# -h, --help Show this help # -h, --help Show this help
# --clean Clean before build # --clean Clean before build
# --full Full rebuild (autoreconf + configure + make) # --full Full rebuild (autoreconf + configure + make)
# --asan Build with AddressSanitizer (debug)
# -j[N] Build with N parallel jobs (default: 4) # -j[N] Build with N parallel jobs (default: 4)
set -e # Exit on error set -e # Exit on error
@ -21,6 +22,7 @@ fi
# Parse arguments # Parse arguments
CLEAN=0 CLEAN=0
FULL_REBUILD=0 FULL_REBUILD=0
USE_ASAN=0
JOBS="-j4" JOBS="-j4"
MAKE_ARGS="" MAKE_ARGS=""
@ -32,6 +34,7 @@ while [[ $# -gt 0 ]]; do
echo " -h, --help Show this help" echo " -h, --help Show this help"
echo " --clean Clean before build" echo " --clean Clean before build"
echo " --full Full rebuild (autoreconf + configure + make)" echo " --full Full rebuild (autoreconf + configure + make)"
echo " --asan Build with AddressSanitizer"
echo " -j[N] Build with N parallel jobs (default: 4)" echo " -j[N] Build with N parallel jobs (default: 4)"
exit 0 exit 0
;; ;;
@ -43,6 +46,10 @@ while [[ $# -gt 0 ]]; do
FULL_REBUILD=1 FULL_REBUILD=1
shift shift
;; ;;
--asan)
USE_ASAN=1
shift
;;
-j*) -j*)
JOBS="$1" JOBS="$1"
shift shift
@ -126,16 +133,29 @@ fi
if [ ! -f Makefile ]; then if [ ! -f Makefile ]; then
echo "" echo ""
echo "Running ./configure..." echo "Running ./configure..."
./configure if [ "$USE_ASAN" -eq 1 ]; then
./configure CFLAGS="-g -Og -fsanitize=address -fno-omit-frame-pointer -fno-pie" LDFLAGS="-no-pie"
else
./configure
fi
fi fi
# Build (all .o files go to build/ directory, binary copied to project root) # Build (all .o files go to build/ directory, binary copied to project root)
echo "" echo ""
echo "Compiling with $JOBS..." echo "Compiling with $JOBS..."
BUILD_SUCCESS=0 BUILD_SUCCESS=0
make $JOBS $MAKE_ARGS 2>&1 | tee build.log if [ "$USE_ASAN" -eq 1 ]; then
if [ ${PIPESTATUS[0]} -eq 0 ]; then echo "(AddressSanitizer enabled — lib/ and src/ only, skipping tests)"
AF="-fsanitize=address -fno-omit-frame-pointer -g -Og"
AL="-fsanitize=address"
(cd lib && make clean $JOBS $MAKE_ARGS 2>&1 && make "CFLAGS+=$AF" "LDFLAGS+=$AL" $JOBS $MAKE_ARGS 2>&1) || { echo "lib build failed"; exit 1; }
(cd src && make clean $JOBS $MAKE_ARGS 2>&1 && make "CFLAGS+=$AF" "LDFLAGS+=$AL" $JOBS $MAKE_ARGS 2>&1) || { echo "src build failed"; exit 1; }
BUILD_SUCCESS=1 BUILD_SUCCESS=1
else
make $JOBS $MAKE_ARGS 2>&1 | tee build.log
if [ ${PIPESTATUS[0]} -eq 0 ]; then
BUILD_SUCCESS=1
fi
fi fi
if [ $BUILD_SUCCESS -eq 1 ]; then if [ $BUILD_SUCCESS -eq 1 ]; then

10
lib/tcp_io.c

@ -127,11 +127,11 @@ void tcp_conn_destroy(struct tcp_conn* tc) {
if (e->dgram && e->dgram != &tcp_fin_sentinel) memory_pool_free(tc->data_pool, e->dgram); if (e->dgram && e->dgram != &tcp_fin_sentinel) memory_pool_free(tc->data_pool, e->dgram);
queue_entry_free(e); queue_resume_callback(tc->write_queue); queue_entry_free(e); queue_resume_callback(tc->write_queue);
} }
queue_free(tc->read_queue); queue_free(tc->read_queue); tc->read_queue = NULL;
queue_free(tc->write_queue); queue_free(tc->write_queue); tc->write_queue = NULL;
if (tc->write_buf) memory_pool_free(tc->data_pool, tc->write_buf); if (tc->write_buf) memory_pool_free(tc->data_pool, tc->write_buf);
if (tc->sock != SOCKET_INVALID) socket_close_wrapper(tc->sock); if (tc->sock != SOCKET_INVALID) { socket_close_wrapper(tc->sock); tc->sock = SOCKET_INVALID; }
memory_pool_destroy(tc->entry_pool); memory_pool_destroy(tc->entry_pool);
memory_pool_destroy(tc->data_pool); memory_pool_destroy(tc->data_pool);
u_free(tc); u_free(tc);
@ -185,7 +185,7 @@ static void tcp_conn_handle_error(struct tcp_conn* tc, int err)
static void read_cb(socket_t sock, void* arg) { static void read_cb(socket_t sock, void* arg) {
(void)sock; (void)sock;
struct tcp_conn* tc = (struct tcp_conn*)arg; struct tcp_conn* tc = (struct tcp_conn*)arg;
if (!tc || tc->sock == SOCKET_INVALID) return; if (!tc || tc->sock == SOCKET_INVALID || !tc->read_queue) return;
struct ll_entry* e = queue_entry_new_from_pool(tc->entry_pool); struct ll_entry* e = queue_entry_new_from_pool(tc->entry_pool);
uint8_t* buf = memory_pool_alloc(tc->data_pool); uint8_t* buf = memory_pool_alloc(tc->data_pool);
@ -368,7 +368,7 @@ static void write_queue_fetch_cb(struct ll_queue* q, void* arg) {
static void write_cb(socket_t sock, void* arg) { static void write_cb(socket_t sock, void* arg) {
(void)sock; (void)sock;
struct tcp_conn* tc = (struct tcp_conn*)arg; struct tcp_conn* tc = (struct tcp_conn*)arg;
if (!tc || tc->sock == SOCKET_INVALID) return; if (!tc || tc->sock == SOCKET_INVALID || !tc->write_queue) return;
if (!tc->connected) { if (!tc->connected) {
int err = 0; int err = 0;

Loading…
Cancel
Save