[Mapserver-dev] copyProperty in mapserver

Sean Gillies sgillies at frii.com
Sun May 30 17:11:26 EDT 2004


On May 30, 2004, at 1:19 PM, Mladen Turk wrote:

> Hi all,
>
> There are a couple of issues dealing with mapCopy caused by the 
> copyProperty
> calls.
>
> The first one is caused by using copyStringProperty, that in almost all
> cases should be changed to copyStringPropertyRealloc.
>
> The reason is cause the fist one simply assigns the pointers while the 
> other
> does a strdup. Later on when the object is freed, the same string gets 
> freed
> twice, and that makes the things crash.
>
> For example the copySymbol (see bug #640), or the #700 for copyWeb is 
> caused
> by the same problem (see the patches).
>
> So, for all dynamic strings the copyStringPropertyRealloc should be 
> used.
>
> Also there is a heavily use of copyProperty for simple integral data 
> types
> like integers, pointers, etc.
> Using memcpy for such integral types is way too much overhead though. 
> Simple
> integer assignment is replaced with at least 2 function calls.
> It also makes the code totally unreadable.
>
> For example I found my self thinking about the:
>   copyProperty(&(dst->map), &map, sizeof(mapObj *));
> that is in fact the:
>   dst->map = map;
>
> Very amusing :-)
>
>
> Also I propose that the copyStringPropertRealloc gets replaced by the 
> simple
> macro:
>
> #define STRDUPX(os, ns)         \
>     do {                        \
>         if ((os) != NULL)       \
>             msFree((os));       \
>         (os) = strdup((ns));    \
>     } while (0)
>
> Then one can simply use the:
> STRDUPX(dst->imagepath, src->imagepath);
>
> And for character arrays simply use the strcpy.
>
>
> MT.
>

Hey MT.,

I wrote the copyProperty function because I had intent to do more checks
on variables, error handling, and to copy structs.  That stuff never
came to pass, so you are right, simple assignment is much better.

Maybe I'll be able to close bug 640 tomorrow.  Thanks for the 
contribution!

cheers,
Sean

--
Sean Gillies
sgillies at frii dot com
http://users.frii.com/sgillies




More information about the mapserver-dev mailing list