Skip to content

Fix Memory leak when pushing event for READ_WRITE attribute

Closes #1292, #1265, #904

The origin of the leak is this check in the event firing process. We suppose to delete set value in case if nobody is listen to the event (or some other cases), but we did not do it for writable scalar attribute. The origin of this, in turn was the fact, that for whatever reason for the case of writable scalar attribute we did not make value sequence at the Attribute::set_value (e.g. here, here, e.t.c for all types), but we did it later, when we enter Attribute::add_write_value (e.g. here and e.t.c for all types) which executed only when we readout value. So it just was not possible to delete it. And at the same time it explains, why it does not leak when there is subscriber.

I did not find any reasonable explanation, why writable attributes should be treated different, so I changed the way, how we handle them: now we create the value seq already at set_value (as for read only) and when we add written value, we just extend value seq and add written value.

I also had to re-write WAttribute::check_rds_alarm(), Attribute::check_level_alarm() and Attribute::check_warn_alarm() in order no to use tmp values. I also made helper template method, since their code was looking ridiculous (and now attibute.cpp is 1500 lines shorter)

PS now I think, that the origin of original code was, that when we extend value, we, probably, do one more copy...

Edited by Yury Matveyev

Merge request reports