Hi Arnau,
sorry, but this is very likely not correct. The refcount must be increased. I'd check why there's only one call to ad_close() if the refcount is larger then one.