If channel is NULL, free them all (for shutdown) */
| 2524 | |
| 2525 | /* If channel is NULL, free them all (for shutdown) */ |
| 2526 | void free_htlcs(struct lightningd *ld, const struct channel *channel) |
| 2527 | { |
| 2528 | struct htlc_out_map_iter outi; |
| 2529 | struct htlc_out *hout; |
| 2530 | struct htlc_in_map_iter ini; |
| 2531 | struct htlc_in *hin; |
| 2532 | bool deleted; |
| 2533 | |
| 2534 | /* FIXME: Implement check_htlcs to ensure no dangling hout->in ptrs! */ |
| 2535 | |
| 2536 | do { |
| 2537 | deleted = false; |
| 2538 | for (hout = htlc_out_map_first(&ld->htlcs_out, &outi); |
| 2539 | hout; |
| 2540 | hout = htlc_out_map_next(&ld->htlcs_out, &outi)) { |
| 2541 | if (channel && hout->key.channel != channel) |
| 2542 | continue; |
| 2543 | tal_free(hout); |
| 2544 | deleted = true; |
| 2545 | } |
| 2546 | |
| 2547 | for (hin = htlc_in_map_first(&ld->htlcs_in, &ini); |
| 2548 | hin; |
| 2549 | hin = htlc_in_map_next(&ld->htlcs_in, &ini)) { |
| 2550 | if (channel && hin->key.channel != channel) |
| 2551 | continue; |
| 2552 | tal_free(hin); |
| 2553 | deleted = true; |
| 2554 | } |
| 2555 | /* Can skip over elements due to iterating while deleting. */ |
| 2556 | } while (deleted); |
| 2557 | } |
| 2558 | |
| 2559 | /* BOLT #2: |
| 2560 | * |
no test coverage detected