fix: disconnect back-forward list signal from correct object
Store back-forward list reference and its signal ID separately. Disconnect from the correct object (back-forward list) instead of WebView to prevent silent disconnection failures that could cause panics or leaks. In GObject, signal handlers must be disconnected from the same object they were connected to.
- commit
- b03b1e994518b28a88a57e9546518e54bc1129db
- author
- brice · · 2026-01-29 05:09 UTC
- parent
- 2255773
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +12 -1
M internal/infrastructure/webkit/webview.go +12 -1
| @@ -163,6 +163,9 @@ type WebView struct { | |||
| 163 | 163 | // findController is cached to prevent GC from collecting the Go wrapper | |
| 164 | 164 | findController *findControllerAdapter | |
| 165 | 165 | findControllerOnce sync.Once | |
| 166 | + | ||
| 167 | + | backForwardList *webkit.BackForwardList | |
| 168 | + | backForwardListSignalID uint32 | |
| 166 | 169 | } | |
| 167 | 170 | ||
| 168 | 171 | type findControllerAdapter struct { | |
| @@ -853,7 +856,8 @@ func (wv *WebView) connectBackForwardListChangedSignal() { | |||
| 853 | 856 | wv.mu.Unlock() | |
| 854 | 857 | } | |
| 855 | 858 | sigID := backForwardList.ConnectChanged(&changedCb) | |
| 856 | - | wv.signalIDs = append(wv.signalIDs, sigID) | |
| 859 | + | wv.backForwardList = backForwardList | |
| 860 | + | wv.backForwardListSignalID = sigID | |
| 857 | 861 | } | |
| 858 | 862 | ||
| 859 | 863 | // ID returns the unique identifier for this WebView. | |
| @@ -1236,6 +1240,13 @@ func (wv *WebView) DisconnectSignals() { | |||
| 1236 | 1240 | } | |
| 1237 | 1241 | wv.signalIDs = wv.signalIDs[:0] // Clear the slice | |
| 1238 | 1242 | ||
| 1243 | + | if wv.backForwardList != nil && wv.backForwardListSignalID != 0 { | |
| 1244 | + | bfObj := gobject.ObjectNewFromInternalPtr(wv.backForwardList.GoPointer()) | |
| 1245 | + | gobject.SignalHandlerDisconnect(bfObj, wv.backForwardListSignalID) | |
| 1246 | + | wv.backForwardListSignalID = 0 | |
| 1247 | + | wv.backForwardList = nil | |
| 1248 | + | } | |
| 1249 | + | ||
| 1239 | 1250 | wv.logger.Debug().Uint64("id", uint64(wv.id)).Msg("signals disconnected") | |
| 1240 | 1251 | } | |
| 1241 | 1252 | ||
| @@ -163,6 +163,9 @@ type WebView struct { | |||||
| 163 | // findController is cached to prevent GC from collecting the Go wrapper | 163 | // findController is cached to prevent GC from collecting the Go wrapper | ||
| 164 | findController *findControllerAdapter | 164 | findController *findControllerAdapter | ||
| 165 | findControllerOnce sync.Once | 165 | findControllerOnce sync.Once | ||
| 166 | + | ||||
| 167 | + | backForwardList *webkit.BackForwardList | |||
| 168 | + | backForwardListSignalID uint32 | |||
| 166 | } | 169 | } | ||
| 167 | 170 | ||||
| 168 | type findControllerAdapter struct { | 171 | type findControllerAdapter struct { | ||
| @@ -853,7 +856,8 @@ func (wv *WebView) connectBackForwardListChangedSignal() { | |||||
| 853 | wv.mu.Unlock() | 856 | wv.mu.Unlock() | ||
| 854 | } | 857 | } | ||
| 855 | sigID := backForwardList.ConnectChanged(&changedCb) | 858 | sigID := backForwardList.ConnectChanged(&changedCb) | ||
| 856 | - | wv.signalIDs = append(wv.signalIDs, sigID) | 859 | + | wv.backForwardList = backForwardList |
| 860 | + | wv.backForwardListSignalID = sigID | |||
| 857 | } | 861 | } | ||
| 858 | 862 | ||||
| 859 | // ID returns the unique identifier for this WebView. | 863 | // ID returns the unique identifier for this WebView. | ||
| @@ -1236,6 +1240,13 @@ func (wv *WebView) DisconnectSignals() { | |||||
| 1236 | } | 1240 | } | ||
| 1237 | wv.signalIDs = wv.signalIDs[:0] // Clear the slice | 1241 | wv.signalIDs = wv.signalIDs[:0] // Clear the slice | ||
| 1238 | 1242 | ||||
| 1243 | + | if wv.backForwardList != nil && wv.backForwardListSignalID != 0 { | |||
| 1244 | + | bfObj := gobject.ObjectNewFromInternalPtr(wv.backForwardList.GoPointer()) | |||
| 1245 | + | gobject.SignalHandlerDisconnect(bfObj, wv.backForwardListSignalID) | |||
| 1246 | + | wv.backForwardListSignalID = 0 | |||
| 1247 | + | wv.backForwardList = nil | |||
| 1248 | + | } | |||
| 1249 | + | ||||
| 1239 | wv.logger.Debug().Uint64("id", uint64(wv.id)).Msg("signals disconnected") | 1250 | wv.logger.Debug().Uint64("id", uint64(wv.id)).Msg("signals disconnected") | ||
| 1240 | } | 1251 | } | ||
| 1241 | 1252 | ||||