ソースを参照

[tcp] Discard all TCP connections on shutdown

Allow detection of genuine memory leaks by ensuring that all TCP
connections are freed on shutdown.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12年前
コミット
8a0331c29b
1個のファイルの変更22行の追加0行の削除
  1. 22
    0
      src/net/tcp.c

+ 22
- 0
src/net/tcp.c ファイルの表示

@@ -7,6 +7,7 @@
7 7
 #include <ipxe/timer.h>
8 8
 #include <ipxe/iobuf.h>
9 9
 #include <ipxe/malloc.h>
10
+#include <ipxe/init.h>
10 11
 #include <ipxe/retry.h>
11 12
 #include <ipxe/refcnt.h>
12 13
 #include <ipxe/xfer.h>
@@ -343,6 +344,7 @@ static void tcp_close ( struct tcp_connection *tcp, int rc ) {
343 344
 
344 345
 		/* Remove from list and drop reference */
345 346
 		stop_timer ( &tcp->timer );
347
+		stop_timer ( &tcp->wait );
346 348
 		list_del ( &tcp->list );
347 349
 		ref_put ( &tcp->refcnt );
348 350
 		DBGC ( tcp, "TCP %p connection deleted\n", tcp );
@@ -1261,6 +1263,26 @@ struct cache_discarder tcp_cache_discarder __cache_discarder = {
1261 1263
 	.discard = tcp_discard,
1262 1264
 };
1263 1265
 
1266
+/**
1267
+ * Shut down all TCP connections
1268
+ *
1269
+ */
1270
+static void tcp_shutdown ( int booting __unused ) {
1271
+	struct tcp_connection *tcp;
1272
+
1273
+	while ( ( tcp = list_first_entry ( &tcp_conns, struct tcp_connection,
1274
+					   list ) ) != NULL ) {
1275
+		tcp->tcp_state = TCP_CLOSED;
1276
+		tcp_dump_state ( tcp );
1277
+		tcp_close ( tcp, -ECANCELED );
1278
+	}
1279
+}
1280
+
1281
+/** TCP shutdown function */
1282
+struct startup_fn tcp_startup_fn __startup_fn ( STARTUP_EARLY ) = {
1283
+	.shutdown = tcp_shutdown,
1284
+};
1285
+
1264 1286
 /***************************************************************************
1265 1287
  *
1266 1288
  * Data transfer interface

読み込み中…
キャンセル
保存