Ack.

Thanks,
Ramesh.

On 9/11/2014 5:06 PM, Anders Widell wrote:
>   osaf/libs/core/common/osaf_extended_name.c |  25 +++++++++++++++++++++----
>   1 files changed, 21 insertions(+), 4 deletions(-)
>
>
> The string pointer stored inside the SaNameT structure for long DNs (longer 
> than
> 255 bytes) was not detected by Valgrind, since it was not stored on an aligned
> address. This had the effect that allocated memory may have been reported as
> "definitely lost" rather than "still reachable" by the Valgrind memory leak
> detection.
>
> The fix is to store the pointer at an aligned address. It will only work when
> the SaNameT structure itself is stored at an aligned address (which is not
> guaranteed since it contains nothing larger than an 16-bit integer), but it
> should work in many cases.
>
> diff --git a/osaf/libs/core/common/osaf_extended_name.c 
> b/osaf/libs/core/common/osaf_extended_name.c
> --- a/osaf/libs/core/common/osaf_extended_name.c
> +++ b/osaf/libs/core/common/osaf_extended_name.c
> @@ -24,6 +24,18 @@
>   #include "osaf_extended_name.h"
>   #include "ncsgl_defs.h"
>   
> +enum {
> +     /* Index in the SaNameT._opaque array where the string pointer will be
> +        stored when the distinguished name is longer than 255 bytes. By
> +        storing the pointer at an aligned address, Valgrind will be able to
> +        detect the pointer and thus the memory leak detection in Valgrind
> +        will work with these strings. Note though that since the largest
> +        member in the SaNameT structure is a 16-bit integer, there is no
> +        guarantee that the SaNameT structure itself is stored at an aligned
> +        address. */
> +     kExtendedNamePointerOffset = sizeof(SaConstStringT) / sizeof(SaUint16T)
> +};
> +
>   static inline SaConstStringT get_ptr(const SaNameT* name);
>   static inline void set_ptr(SaConstStringT value, SaNameT* name);
>   
> @@ -36,7 +48,8 @@ static inline SaConstStringT get_ptr(con
>               SaConstStringT pointer;
>               SaUint8T bytes[sizeof(SaConstStringT)];
>       } tmp;
> -     memcpy(tmp.bytes, name->_opaque + 1, sizeof(SaConstStringT));
> +     memcpy(tmp.bytes, name->_opaque + kExtendedNamePointerOffset,
> +             sizeof(SaConstStringT));
>       return tmp.pointer;
>   }
>   
> @@ -48,7 +61,8 @@ static inline void set_ptr(SaConstString
>       } tmp;
>       tmp.pointer = value;
>       name->_opaque[0] = kExtendedNameMagic;
> -     memcpy(name->_opaque + 1, tmp.bytes, sizeof(SaConstStringT));
> +     memcpy(name->_opaque + kExtendedNamePointerOffset, tmp.bytes,
> +             sizeof(SaConstStringT));
>   }
>   
>   void osaf_extended_name_init(void)
> @@ -135,7 +149,9 @@ size_t osaf_extended_name_length(const S
>   void osaf_extended_name_clear(SaNameT* name)
>   {
>       name->_opaque[0] = 0;
> -     memset(name->_opaque + 1, 0, sizeof(SaConstStringT));
> +     *(char*) (name->_opaque + 1) = '\0';
> +     memset(name->_opaque + kExtendedNamePointerOffset, 0,
> +             sizeof(SaConstStringT));
>   }
>   
>   void osaf_extended_name_steal(SaStringT value, SaNameT* name)
> @@ -179,6 +195,7 @@ void osaf_extended_name_free(SaNameT* na
>                       free((SaStringT*) get_ptr(name));
>               }
>               name->_opaque[0] = 0xffff;
> -             memset(name->_opaque + 1, 0, sizeof(SaConstStringT));
> +             memset(name->_opaque + kExtendedNamePointerOffset, 0,
> +                     sizeof(SaConstStringT));
>       }
>   }


------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to