File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -1472,12 +1472,17 @@ static int remove_peer(struct peer *peer)
1472
1472
memmove (ctx -> peers + idx , ctx -> peers + idx + 1 ,
1473
1473
(ctx -> num_peers - idx ) * sizeof (struct peer * ));
1474
1474
1475
- tmp = realloc (ctx -> peers , ctx -> num_peers * sizeof (struct peer * ));
1476
- if (!tmp && ctx -> num_peers ) {
1477
- warn ("%s: peer realloc(reduce!) failed" , __func__ );
1478
- // we'll re-try on next add/remove
1475
+ if (ctx -> num_peers > 0 ) {
1476
+ tmp = realloc (ctx -> peers , ctx -> num_peers * sizeof (struct peer * ));
1477
+ if (!tmp ) {
1478
+ warn ("%s: peer realloc(reduce!) failed" , __func__ );
1479
+ // we'll re-try on next add/remove
1480
+ } else {
1481
+ ctx -> peers = tmp ;
1482
+ }
1479
1483
} else {
1480
- ctx -> peers = tmp ;
1484
+ free (ctx -> peers );
1485
+ ctx -> peers = NULL ;
1481
1486
}
1482
1487
1483
1488
free (peer );
You can’t perform that action at this time.
0 commit comments