I checked and it isn't overwriting the segment_table area and really tries to free the unused segments (returns result 0 for each exos 25). But I had to free $ff to get no memory errors when opening channel and loading... Although I freed $fa and $fb earlier... But it's only a workaround...
Well, I guess the problem here that you allocate all the segments in the system throughout your loop, in this situation the next allocate segment will not fail but provides the so called shared segment, the system segment itself, "split" at an address (this is called the EXOS boundary) between the system (ie EXOS) and you. The segment allocation EXOS call (function 24) can result in three "type of outcome":
1. If there is at least one free segment, it will be allocated for you, segment number is returned, status of the call is OK
2. If there is no free segment left, but shared segment is not allocated yet, then the call itself will return with status "error" as "SHARE" (can't remember the exact code for this in register A now), but actually it's not an error like other kind of error, but only a fact, that no "whole" free segment in the system remain so the system segment is provided for the user with the EXOS boundary in DE showing the address where it is split (so above that address within the segment should not be written otherwise your overwrite EXOS areas ...). However if you exploit this, system segment can't "grow" (downwards) anymore, thus functions need more memory by EXOS will fail (like maybe the open channel ...). There is EXOS call where you can set EXOS boundary so leave some additional memory for EXOS, since in case of shared segment is allocated, the EXOS boundary (I guess) is set in a way that all the non-used memory can be used within the shared segment by the user (so can't grow by EXOS). As far as I know, shared segment is not needed to be segment $FF, it's possible that already more than 16K of memory is used by EXOS, then the shared segment situation will happen in segment $FE for example. So don't assume register C is $FF in case of shared segment, but use value i register C.
3. There is no free "whole" segment and _also_ the shared segment is already allocated, in this case "NOSEG" error is returned.
Some may think that segment allocation actually can have only two results, allocated segment, or error, but it's not the case as you can see.
Anyway: if you need the workaround to free segment $FF it means that you exhausted all of the segments in the system, and even shared segment _is_ allocated, so you need to free. I guess, if you stop your allocation loop when you got the first video seg (C >= $FC). well, if you need only one video segment of course

Anyway, I write just too much, I'm sorry

What I am not sure about at all: what happens if you allocate ALL segments (including the shared!) and then free all the segments, but not the shared segment. In this case though many segments can be available, _I guess_ EXOS won't work too much, because system segment can't grow downwards (I don't know if EXOS has the ability to "jump" over and continue its tasks at a lower numbered video segment, I guess it can't, since the rule that there is exactly one shared segment or none in the system, but if EXOS would be able to do this, you can also create another shared segment then). Well, EXOS is quite complicated sometimes

But in a good way, just not so easy to understand. At least, this is _my_ opinion
