On Fri, May 7, 2010 at 2:59 PM, Sebastian Dransfeld <[email protected]> wrote: > Gustavo Sverzut Barbieri wrote: >> >> On Thu, May 6, 2010 at 5:50 PM, Enlightenment SVN >> <[email protected]> wrote: >>> >>> Log: >>> e_dbus/hal: remove stringshare madness >> >> Errr... I may be wrong, but I guess NOW it is wrong. >> >> >>> @@ -31,8 +30,7 @@ >>> switch(type) >>> { >>> case DBUS_TYPE_STRING: >>> - dbus_message_iter_get_basic(&iter, &tmp); >>> - ret->val.s = eina_stringshare_add(tmp); >>> + dbus_message_iter_get_basic(&iter, &(ret->val.s)); >>> break; >>> case DBUS_TYPE_INT32: >>> dbus_message_iter_get_basic(&iter, &(ret->val.i)); >> >> what was wrong and mad about it? >> >> >> http://dbus.freedesktop.org/doc/api/html/group__DBusMessage.html#g580376979e156abe06bbb3ccc3fc6d4c >> >> dbus_message_iter_get_basic(): >> "The returned value is by reference and should not be freed" >> >> So clearly it is a reference to the DBus INTERNAL memory, and should >> not be trusted after the message is gone, as it will depend on its >> internal garbage collection and buffer management. >> >> Having ret->val.s alive after the message iterator is changed is just >> pure luck. You must add it to a stringshare or strdup() it, I'd rather >> do the later. >> >> If there was something else wrong with this code, fix it instead. This >> commit is clearly wrong. >> >> > > I think the most important bit to do before changing code is to understand > the code. Almost all code inside e_hal happens during a dbus msg callback. > So during this message callback the dbus message exists, and all internal > memory for the message exists. > > The right place to do the stringshare is during the personal callback > handler as it was before and as it is now.
Just to make it to the list for further reference, as said at IRC we do keep these strings longer and there is no guarantee they will be alive, they happen to do, but there is no guarantee. BR, -- Gustavo Sverzut Barbieri http://profusion.mobi embedded systems -------------------------------------- MSN: [email protected] Skype: gsbarbieri Mobile: +55 (19) 9225-2202 ------------------------------------------------------------------------------ _______________________________________________ enlightenment-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/enlightenment-devel
