fixed little memory leaks during load/unload of control unit. Improved also other things into common layer

Signed-off-by: Claudio Bisegni <Claudio.Bisegni@lnf.infn.it>