Make DelteProfile and ShutdownPeer safe to call twice / with incorrect onion
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Sarah Jamie Lewis 2023-04-21 14:21:49 -07:00
parent 48e5f44f84
commit 8ab0e9993a
1 changed files with 13 additions and 0 deletions

View File

@ -255,6 +255,12 @@ func (app *application) DeleteProfile(onion string, password string) {
app.appmutex.Lock()
defer app.appmutex.Unlock()
// short circuit to prevent nil-pointer panic if this function is called twice (or incorrectly)
if app.peers[onion] == nil {
log.Errorf("shutdownPeer called with invalid onion %v", onion)
return
}
// allow a blank password to delete "unencrypted" accounts...
if password == "" {
password = DefactoPasswordForUnencryptedProfiles
@ -477,6 +483,13 @@ func (app *application) ShutdownPeer(onion string) {
// shutdownPeer mutex unlocked helper shutdown peer
func (app *application) shutdownPeer(onion string) {
// short circuit to prevent nil-pointer panic if this function is called twice (or incorrectly)
if app.eventBuses[onion] == nil || app.peers[onion] == nil {
log.Errorf("shutdownPeer called with invalid onion %v", onion)
return
}
app.eventBuses[onion].Publish(event.NewEventList(event.ShutdownPeer, event.Identity, onion))
app.eventBuses[onion].Shutdown()
delete(app.eventBuses, onion)