http://www.inventati.org/noname/dillo/chain-cleanup.patch 1. Replaced dNew with dMalloc and dNew0 with dMalloc0. This way it is possible to use (sizeof *var) instead of repeating variable type. By the way, when 'count' is constant, dMalloc is easier to use, and when count is not constant, integer overflow can happen in dNew during multiplication. It looks like there are no such errors, but I think check should be added or, better, dCalloc can be introduced so libc checks for such cases. 2. Replaced #defines with enums and made them uppercase so it is easier to distinguish them from variables. This style is already used in most modules. IO should be fixed too, probably. 3. Moved duplicate code from a_Chain_fcb and a_Chain_bcb to Chain_cb. Anonymous structures for connections (forward or backward) are introduced in ChainLink structure for this purpose. 4. Removed unused a_Chain_unlink function. Chain links are just dFreed instead. Anyway, there is no function to connect existing links back, so disconnected link can only be dFreed. 5. Replaced AtoB_branch and BtoA_branch parameters of a_Chain_link_new with single Branch parameter. They were always equal anyway, and using different branch identifiers for one connection makes no sense, as branch ID is used to distinguish between Answer and Query chains. Branch parameter can be eliminated completely by separating existing CCC callbacks into answer and query callbacks. Currently instead of two functions we have one with if (Branch == 1) { ... } else { ... }