If channel is NULL, free them all (for shutdown) */
| 2816 | |
| 2817 | /* If channel is NULL, free them all (for shutdown) */ |
| 2818 | void free_htlcs(struct lightningd *ld, const struct channel *channel) |
| 2819 | { |
| 2820 | struct htlc_out_map_iter outi; |
| 2821 | struct htlc_out *hout; |
| 2822 | struct htlc_in_map_iter ini; |
| 2823 | struct htlc_in *hin; |
| 2824 | bool deleted; |
| 2825 | |
| 2826 | /* FIXME: Implement check_htlcs to ensure no dangling hout->in ptrs! */ |
| 2827 | |
| 2828 | do { |
| 2829 | deleted = false; |
| 2830 | for (hout = htlc_out_map_first(ld->htlcs_out, &outi); |
| 2831 | hout; |
| 2832 | hout = htlc_out_map_next(ld->htlcs_out, &outi)) { |
| 2833 | if (channel && hout->key.channel != channel) |
| 2834 | continue; |
| 2835 | tal_free(hout); |
| 2836 | deleted = true; |
| 2837 | } |
| 2838 | |
| 2839 | for (hin = htlc_in_map_first(ld->htlcs_in, &ini); |
| 2840 | hin; |
| 2841 | hin = htlc_in_map_next(ld->htlcs_in, &ini)) { |
| 2842 | if (channel && hin->key.channel != channel) |
| 2843 | continue; |
| 2844 | tal_free(hin); |
| 2845 | deleted = true; |
| 2846 | } |
| 2847 | /* Can skip over elements due to iterating while deleting. */ |
| 2848 | } while (deleted); |
| 2849 | } |
| 2850 | |
| 2851 | /* BOLT #2: |
| 2852 | * |
no test coverage detected