MT#7347 added reference counting to plug-in interfaces.

ported patch from 1.4-ha-sw branch of sems-ha.

(cherry picked from commit fc3b31c134468b39a689e0379d01441ab76cb7bf)
MT#7347 fix broken build (scope issues with GCC).

(cherry picked from commit 5fab0995ddaacb0b90fcef1b136b8127d75c0993)