# HG changeset patch # User Paul Boddie # Date 1631382297 -7200 # Node ID 31144210aa37014b371f041e269d60204ce96f2e # Parent b3cae22cced5739a83398b6c80cb932247d84901 Introduced deletion of pipe paging objects, previously neglected. diff -r b3cae22cced5 -r 31144210aa37 libfsserver/include/fsserver/pipe_paging.h --- a/libfsserver/include/fsserver/pipe_paging.h Sat Sep 11 01:32:34 2021 +0200 +++ b/libfsserver/include/fsserver/pipe_paging.h Sat Sep 11 19:44:57 2021 +0200 @@ -68,7 +68,9 @@ public: explicit PipePaging(Memory *memory, offset_t size); - virtual void detach(); + virtual ~PipePaging(); + + virtual unsigned int detach(); virtual offset_t region_size() { return _size; } diff -r b3cae22cced5 -r 31144210aa37 libfsserver/lib/pipes/pipe_pager.cc --- a/libfsserver/lib/pipes/pipe_pager.cc Sat Sep 11 01:32:34 2021 +0200 +++ b/libfsserver/lib/pipes/pipe_pager.cc Sat Sep 11 19:44:57 2021 +0200 @@ -60,11 +60,22 @@ void PipePager::close() { - _paging->detach(); + if (_paging == NULL) + return; + + unsigned int attached = _paging->detach(); /* Notify the other endpoint. */ _paging->notify_others(_writing ? PipePaging::WRITER : PipePaging::READER, NOTIFY_PEER_CLOSED); + + /* Deallocate the paging coordinator if no other endpoints are active. */ + + if (!attached) + { + delete _paging; + _paging = NULL; + } } /* Support paging. */ diff -r b3cae22cced5 -r 31144210aa37 libfsserver/lib/pipes/pipe_paging.cc --- a/libfsserver/lib/pipes/pipe_paging.cc Sat Sep 11 01:32:34 2021 +0200 +++ b/libfsserver/lib/pipes/pipe_paging.cc Sat Sep 11 19:44:57 2021 +0200 @@ -46,39 +46,8 @@ _next_region(); } -/* Return whether one or more endpoints have detached. */ - -int PipePaging::closed() -{ - return _active_endpoints < 2; -} - -void PipePaging::discard_region(unsigned int i) +PipePaging::~PipePaging() { - PageMapper *mapper = _regions[i]; - - if (mapper != NULL) - { - mapper->detach(); - _regions[i] = NULL; - delete mapper; - } -} - -/* Detach one endpoint. */ - -void PipePaging::detach() -{ - if (!_active_endpoints) - return; - else - _active_endpoints--; - - /* Return if the other endpoint is attached. */ - - if (_active_endpoints) - return; - /* Discard all regions from the pipe. */ for (unsigned int i = 0; i < 2; i++) @@ -95,6 +64,37 @@ delete _memory; } +/* Return whether one or more endpoints have detached. */ + +int PipePaging::closed() +{ + return _active_endpoints < 2; +} + +/* Detach one endpoint, returning the number still active. */ + +unsigned int PipePaging::detach() +{ + if (_active_endpoints) + _active_endpoints--; + + return _active_endpoints; +} + +/* Discard a region. */ + +void PipePaging::discard_region(unsigned int i) +{ + PageMapper *mapper = _regions[i]; + + if (mapper != NULL) + { + mapper->detach(); + _regions[i] = NULL; + delete mapper; + } +} + /* Add a region to the sequence. */ PageMapper *PipePaging::_add_region()