Prevent a segfault if multiple circuits are freed upon 'quit'

by checking if a 'recent_deck' that is to be freed also exists
with same address in ci_mcdeck of another circuit. If yes, set
this to NULL before freeing.
This commit is contained in:
Holger Vogt 2018-09-25 23:46:16 +02:00
parent a17de08b5c
commit ae89381bb6
1 changed files with 9 additions and 3 deletions

View File

@ -342,13 +342,19 @@ void
inp_mc_free(void)
{
if (ft_curckt && ft_curckt->ci_mcdeck) {
if (recent_deck && recent_deck != ft_curckt->ci_mcdeck)
if (recent_deck && recent_deck != ft_curckt->ci_mcdeck) {
struct circ *pp;
/* NULL any ci_mcdeck entry from ft_circuits whose address equals recent_deck,
then free this address */
for (pp = ft_circuits; pp; pp = pp->ci_next)
if (pp->ci_mcdeck == recent_deck) {
pp->ci_mcdeck = NULL;
}
line_free(recent_deck, TRUE);
}
recent_deck = ft_curckt->ci_mcdeck;
ft_curckt->ci_mcdeck = NULL;
}
else
fprintf(stderr, "Error: No circuit loaded\n");
}
/* called by com_rset: reload most recent circuit */