Add finalize() to socket modules.
Some code cleanup socket modules.