On Sat, Mar 13, 2010 at 6:01 PM, Enlightenment SVN
<[email protected]> wrote:
> Log:
> Use eina_stringshare_replace to avoid crashes.
And a special note, particularly to Raster that takes some time to get
used to new APIs ;-)
the problem with the old approach is that the reference count can drop
to zero, so you must first inc then dec, to avoid that. See the
following test case:
const char *a = eina_stringshare_add("unique string"); // refcount = 1
// using the old and incorrect way: setting "a" where "a" as used:
eina_stringshare_del(a); // refcount = 0
eina_stringshare_add(a); // refcount = 1, but bogus... since the
content of a was freed already.
// using the correct approach, the same that replace does:
tmp = eina_stringshare_add(a); // refcount = 2
eina_stringshare_del(a); // refcount = 1
a = tmp; // refcount = 1
This is a simplification, using the same variable names it is clearly
stupid, but you have different variables with the same pointer in real
code.
--
Gustavo Sverzut Barbieri
http://profusion.mobi embedded systems
--------------------------------------
MSN: [email protected]
Skype: gsbarbieri
Mobile: +55 (19) 9225-2202
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel