#include "smbd/globals.h"
#include "lib/util/bitmap.h"
+static void conn_free_internal(connection_struct *conn);
+
+/****************************************************************************
+ * Remove a conn struct from conn->sconn->connections
+ * if not already done.
+****************************************************************************/
+
+static int conn_struct_destructor(connection_struct *conn)
+{
+ if (conn->sconn != NULL) {
+ DLIST_REMOVE(conn->sconn->connections, conn);
+ SMB_ASSERT(conn->sconn->num_connections > 0);
+ conn->sconn->num_connections--;
+ conn->sconn = NULL;
+ }
+ conn_free_internal(conn);
+ return 0;
+}
+
/****************************************************************************
Return the number of open connections.
****************************************************************************/
DLIST_ADD(sconn->connections, conn);
sconn->num_connections++;
+ /*
+ * Catches the case where someone forgets to call
+ * conn_free().
+ */
+ talloc_set_destructor(conn, conn_struct_destructor);
return conn;
}
free_namearray(conn->aio_write_behind_list);
ZERO_STRUCTP(conn);
- talloc_destroy(conn);
}
/****************************************************************************
void conn_free(connection_struct *conn)
{
- if (conn->sconn == NULL) {
- conn_free_internal(conn);
- return;
- }
-
- DLIST_REMOVE(conn->sconn->connections, conn);
- SMB_ASSERT(conn->sconn->num_connections > 0);
- conn->sconn->num_connections--;
-
- conn_free_internal(conn);
+ TALLOC_FREE(conn);
}
/*