[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdepimlibs/kldap
From:       Andre Heinecke <aheinecke () intevation ! de>
Date:       2010-12-06 19:15:37
Message-ID: 20101206191537.AE0C8AC8A4 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1204323 by aheinecke:

Use malloc and free instead of HeapAlloc and HeapFree to avoid problems
with memory allocated differently


 M  +74 -89    wce-ldap-help.h  


--- trunk/KDE/kdepimlibs/kldap/wce-ldap-help.h #1204322:1204323
@@ -35,7 +35,7 @@
     char *dst;
 
     if (!src) return NULL;
-    dst = ( char * )HeapAlloc( GetProcessHeap(), 0, (strlen( src ) + 1) * sizeof(char) );
+    dst = ( char * )malloc( (strlen( src ) + 1) * sizeof(char) );
     if (dst)
         strcpy( dst, src );
     return dst;
@@ -47,7 +47,7 @@
     if (str)
     {
         DWORD len = MultiByteToWideChar( CP_ACP, 0, str, -1, NULL, 0 );
-        if ((ret = ( WCHAR* )HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
+        if ((ret = ( WCHAR* )malloc( len * sizeof(WCHAR) )))
             MultiByteToWideChar( CP_ACP, 0, str, -1, ret, len );
     }
     return ret;
@@ -59,7 +59,7 @@
     if (str)
     {
         DWORD len = WideCharToMultiByte( CP_ACP, 0, str, -1, NULL, 0, NULL, NULL );
-        if ((ret = ( char* )HeapAlloc( GetProcessHeap(), 0, len )))
+        if ((ret = ( char* )malloc( len )))
             WideCharToMultiByte( CP_ACP, 0, str, -1, ret, len, NULL, NULL );
     }
     return ret;
@@ -71,7 +71,7 @@
     if (str)
     {
         DWORD len = WideCharToMultiByte( CP_UTF8, 0, str, -1, NULL, 0, NULL, NULL );
-        if ((ret = ( char * )HeapAlloc( GetProcessHeap(), 0, len )))
+        if ((ret = ( char * )malloc( len )))
             WideCharToMultiByte( CP_UTF8, 0, str, -1, ret, len, NULL, NULL );
     }
     return ret;
@@ -83,27 +83,12 @@
     if (str)
     {
         DWORD len = MultiByteToWideChar( CP_UTF8, 0, str, -1, NULL, 0 );
-        if ((ret = ( WCHAR* )HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
+        if ((ret = ( WCHAR* )malloc( len * sizeof(WCHAR) )))
             MultiByteToWideChar( CP_UTF8, 0, str, -1, ret, len );
     }
     return ret;
 }
 
-static inline void strfreeA( LPSTR str )
-{
-    HeapFree( GetProcessHeap(), 0, str );
-}
-
-static inline void strfreeW( LPWSTR str )
-{
-    HeapFree( GetProcessHeap(), 0, str );
-}
-
-static inline void strfreeU( char *str )
-{
-    HeapFree( GetProcessHeap(), 0, str );
-}
-
 static inline DWORD strarraylenA( LPSTR *strarray )
 {
     LPSTR *p = strarray;
@@ -133,7 +118,7 @@
     if (strarray)
     {
         size  = sizeof(WCHAR*) * (strarraylenA( strarray ) + 1);
-        strarrayW = ( WCHAR** )HeapAlloc( GetProcessHeap(), 0, size );
+        strarrayW = ( WCHAR** )malloc( size );
 
         if (strarrayW)
         {
@@ -155,7 +140,7 @@
     if (strarray)
     {
         size = sizeof(LPSTR) * (strarraylenW( strarray ) + 1);
-        strarrayA = ( char** )HeapAlloc( GetProcessHeap(), 0, size );
+        strarrayA = ( char** )malloc( size );
 
         if (strarrayA)
         {
@@ -177,7 +162,7 @@
     if (strarray)
     {
         size = sizeof(char*) * (strarraylenW( strarray ) + 1);
-        strarrayU = ( char** )HeapAlloc( GetProcessHeap(), 0, size );
+        strarrayU = ( char** )malloc( size );
 
         if (strarrayU)
         {
@@ -199,7 +184,7 @@
     if (strarray)
     {
         size = sizeof(WCHAR*) * (strarraylenU( strarray ) + 1);
-        strarrayW = ( WCHAR ** )HeapAlloc( GetProcessHeap(), 0, size );
+        strarrayW = ( WCHAR ** )malloc( size );
 
         if (strarrayW)
         {
@@ -218,8 +203,8 @@
     if (strarray)
     {
         LPSTR *p = strarray;
-        while (*p) strfreeA( *p++ );
-        HeapFree( GetProcessHeap(), 0, strarray );
+        while (*p) free( *p++ );
+        free( strarray );
     }
 }
 
@@ -228,8 +213,8 @@
     if (strarray)
     {
         LPWSTR *p = strarray;
-        while (*p) strfreeW( *p++ );
-        HeapFree( GetProcessHeap(), 0, strarray );
+        while (*p) free( *p++ );
+        free( strarray );
     }
 }
 
@@ -238,8 +223,8 @@
     if (strarray)
     {
         char **p = strarray;
-        while (*p) strfreeU( *p++ );
-        HeapFree( GetProcessHeap(), 0, strarray );
+        while (*p) free( *p++ );
+        free( strarray );
     }
 }
 
@@ -248,7 +233,7 @@
     struct berval *berval;
     DWORD size = sizeof(struct berval) + bv->bv_len;
 
-    berval = ( struct berval * )HeapAlloc( GetProcessHeap(), 0, size );
+    berval = ( struct berval * )malloc( size );
     if (berval)
     {
         char *val = (char *)berval + sizeof(struct berval);
@@ -275,7 +260,7 @@
     if (bv)
     {
         size = sizeof(struct berval *) * (bvarraylen( bv ) + 1);
-        berval = ( struct berval ** )HeapAlloc( GetProcessHeap(), 0, size );
+        berval = ( struct berval ** )malloc( size );
 
         if (berval)
         {
@@ -292,15 +277,15 @@
 static inline void bvarrayfree( struct berval **bv )
 {
     struct berval **p = bv;
-    while (*p) HeapFree( GetProcessHeap(), 0, *p++ );
-    HeapFree( GetProcessHeap(), 0, bv );
+    while (*p) free( *p++ );
+    free( bv );
 }
 
 static inline LDAPModW *modAtoW( LDAPModA *mod )
 {
     LDAPModW *modW;
 
-    modW = ( LDAPModW *)HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPModW) );
+    modW = ( LDAPModW *)malloc( sizeof(LDAPModW) );
     if (modW)
     {
         modW->mod_op = mod->mod_op;
@@ -318,7 +303,7 @@
 {
     LDAPMod *modU;
 
-    modU = ( LDAPMod * )HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPMod) );
+    modU = ( LDAPMod * )malloc( sizeof(LDAPMod) );
     if (modU)
     {
         modU->mod_op = mod->mod_op;
@@ -338,7 +323,7 @@
         bvarrayfree( mod->mod_vals.modv_bvals );
     else
         strarrayfreeW( mod->mod_vals.modv_strvals );
-    HeapFree( GetProcessHeap(), 0, mod );
+    free( mod );
 }
 
 static inline void modfreeU( LDAPMod *mod )
@@ -347,7 +332,7 @@
         bvarrayfree( mod->mod_vals.modv_bvals );
     else
         strarrayfreeU( mod->mod_vals.modv_strvals );
-    HeapFree( GetProcessHeap(), 0, mod );
+    free( mod );
 }
 
 static inline DWORD modarraylenA( LDAPModA **modarray )
@@ -372,7 +357,7 @@
     if (modarray)
     {
         size = sizeof(LDAPModW*) * (modarraylenA( modarray ) + 1);
-        modarrayW = ( LDAPModW**)HeapAlloc( GetProcessHeap(), 0, size );
+        modarrayW = ( LDAPModW**)malloc( size );
 
         if (modarrayW)
         {
@@ -394,7 +379,7 @@
     if (modarray)
     {
         size = sizeof(LDAPMod*) * (modarraylenW( modarray ) + 1);
-        modarrayU = ( LDAPMod** )HeapAlloc( GetProcessHeap(), 0, size );
+        modarrayU = ( LDAPMod** )malloc( size );
 
         if (modarrayU)
         {
@@ -414,7 +399,7 @@
     {
         LDAPModW **p = modarray;
         while (*p) modfreeW( *p++ );
-        HeapFree( GetProcessHeap(), 0, modarray );
+        free( modarray );
     }
 }
 
@@ -424,7 +409,7 @@
     {
         LDAPMod **p = modarray;
         while (*p) modfreeU( *p++ );
-        HeapFree( GetProcessHeap(), 0, modarray );
+        free( modarray );
     }
 }
 
@@ -436,15 +421,15 @@
 
     if (control->ldctl_value.bv_val)
     {
-        val = ( char* )HeapAlloc( GetProcessHeap(), 0, len );
+        val = ( char* )malloc( len );
         if (!val) return NULL;
         memcpy( val, control->ldctl_value.bv_val, len );
     }
 
-    controlW = ( LDAPControlW* )HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlW) );
+    controlW = ( LDAPControlW* )malloc( sizeof(LDAPControlW) );
     if (!controlW)
     {
-        HeapFree( GetProcessHeap(), 0, val );
+        free( val );
         return NULL;
     }
 
@@ -464,15 +449,15 @@
 
     if (control->ldctl_value.bv_val)
     {
-        val = ( char* )HeapAlloc( GetProcessHeap(), 0, len );
+        val = ( char* )malloc( len );
         if (!val) return NULL;
         memcpy( val, control->ldctl_value.bv_val, len );
     }
 
-    controlA = ( LDAPControlA* )HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlA) );
+    controlA = ( LDAPControlA* )malloc( sizeof(LDAPControlA) );
     if (!controlA)
     {
-        HeapFree( GetProcessHeap(), 0, val );
+        free( val );
         return NULL;
     }
 
@@ -492,15 +477,15 @@
 
     if (control->ldctl_value.bv_val)
     {
-        val = ( char * )HeapAlloc( GetProcessHeap(), 0, len );
+        val = ( char * )malloc( len );
         if (!val) return NULL;
         memcpy( val, control->ldctl_value.bv_val, len );
     }
 
-    controlU = ( LDAPControl* )HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControl) );
+    controlU = ( LDAPControl* )malloc( sizeof(LDAPControl) );
     if (!controlU)
     {
-        HeapFree( GetProcessHeap(), 0, val );
+        free( val );
         return NULL;
     }
 
@@ -520,15 +505,15 @@
 
     if (control->ldctl_value.bv_val)
     {
-        val = ( char* )HeapAlloc( GetProcessHeap(), 0, len );
+        val = ( char* )malloc( len );
         if (!val) return NULL;
         memcpy( val, control->ldctl_value.bv_val, len );
     }
 
-    controlW = ( LDAPControlW* )HeapAlloc( GetProcessHeap(), 0, sizeof(LDAPControlW) );
+    controlW = ( LDAPControlW* )malloc( sizeof(LDAPControlW) );
     if (!controlW)
     {
-        HeapFree( GetProcessHeap(), 0, val );
+        free( val );
         return NULL;
     }
 
@@ -544,9 +529,9 @@
 {
     if (control)
     {
-        strfreeA( control->ldctl_oid );
-        HeapFree( GetProcessHeap(), 0, control->ldctl_value.bv_val );
-        HeapFree( GetProcessHeap(), 0, control );
+        free( control->ldctl_oid );
+        free( control->ldctl_value.bv_val );
+        free( control );
     }
 }
 
@@ -554,9 +539,9 @@
 {
     if (control)
     {
-        strfreeW( control->ldctl_oid );
-        HeapFree( GetProcessHeap(), 0, control->ldctl_value.bv_val );
-        HeapFree( GetProcessHeap(), 0, control );
+        free( control->ldctl_oid );
+        free( control->ldctl_value.bv_val );
+        free( control );
     }
 }
 
@@ -564,9 +549,9 @@
 {
     if (control)
     {
-        strfreeU( control->ldctl_oid );
-        HeapFree( GetProcessHeap(), 0, control->ldctl_value.bv_val );
-        HeapFree( GetProcessHeap(), 0, control );
+        free( control->ldctl_oid );
+        free( control->ldctl_value.bv_val );
+        free( control );
     }
 }
 
@@ -599,7 +584,7 @@
     if (controlarray)
     {
         size = sizeof(LDAPControlW*) * (controlarraylenA( controlarray ) + 1);
-        controlarrayW = ( LDAPControlW ** )HeapAlloc( GetProcessHeap(), 0, size );
+        controlarrayW = ( LDAPControlW ** )malloc( size );
 
         if (controlarrayW)
         {
@@ -621,7 +606,7 @@
     if (controlarray)
     {
         size = sizeof(LDAPControl*) * (controlarraylenW( controlarray ) + 1);
-        controlarrayA = ( LDAPControlA** )HeapAlloc( GetProcessHeap(), 0, size );
+        controlarrayA = ( LDAPControlA** )malloc( size );
 
         if (controlarrayA)
         {
@@ -643,7 +628,7 @@
     if (controlarray)
     {
         size = sizeof(LDAPControl*) * (controlarraylenW( controlarray ) + 1);
-        controlarrayU = ( LDAPControl ** )HeapAlloc( GetProcessHeap(), 0, size );
+        controlarrayU = ( LDAPControl ** )malloc( size );
 
         if (controlarrayU)
         {
@@ -665,7 +650,7 @@
     if (controlarray)
     {
         size = sizeof(LDAPControlW*) * (controlarraylenU( controlarray ) + 1);
-        controlarrayW = (LDAPControlW** )HeapAlloc( GetProcessHeap(), 0, size );
+        controlarrayW = (LDAPControlW** )malloc( size );
 
         if (controlarrayW)
         {
@@ -685,7 +670,7 @@
     {
         LDAPControlA **p = controlarray;
         while (*p) controlfreeA( *p++ );
-        HeapFree( GetProcessHeap(), 0, controlarray );
+        free( controlarray );
     }
 }
 
@@ -695,7 +680,7 @@
     {
         LDAPControlW **p = controlarray;
         while (*p) controlfreeW( *p++ );
-        HeapFree( GetProcessHeap(), 0, controlarray );
+        free( controlarray );
     }
 }
 
@@ -705,7 +690,7 @@
     {
         LDAPControl **p = controlarray;
         while (*p) controlfreeU( *p++ );
-        HeapFree( GetProcessHeap(), 0, controlarray );
+        free( controlarray );
     }
 }
 
@@ -746,9 +731,9 @@
                                clientctrlsW );
 
 exit:
-    strfreeW( dnW );
-    strfreeW( attrW );
-    strfreeW( valueW );
+    free( dnW );
+    free( attrW );
+    free( valueW );
     controlarrayfreeW( serverctrlsW );
     controlarrayfreeW( clientctrlsW );
 
@@ -792,9 +777,9 @@
                              serverctrlsW, clientctrlsW, message );
 
 exit:
-    strfreeW( dnW );
-    strfreeW( attrW );
-    strfreeW( valueW );
+    free( dnW );
+    free( attrW );
+    free( valueW );
     controlarrayfreeW( serverctrlsW );
     controlarrayfreeW( clientctrlsW );
 
@@ -833,7 +818,7 @@
     ret = ldap_modify_ext_sW( ld, dnW, modsW, serverctrlsW, clientctrlsW );
 
 exit:
-    strfreeW( dnW );
+    free( dnW );
     modarrayfreeW( modsW );
     controlarrayfreeW( serverctrlsW );
     controlarrayfreeW( clientctrlsW );
@@ -873,7 +858,7 @@
     ret = ldap_add_ext_sW( ld, dnW, attrsW, serverctrlsW, clientctrlsW );
 
 exit:
-    strfreeW( dnW );
+    free( dnW );
     modarrayfreeW( attrsW );
     controlarrayfreeW( serverctrlsW );
     controlarrayfreeW( clientctrlsW );
@@ -913,7 +898,7 @@
     ret = ldap_add_extW( ld, dnW, attrsW, serverctrlsW, clientctrlsW, message );
 
 exit:
-    strfreeW( dnW );
+    free( dnW );
     modarrayfreeW( attrsW );
     controlarrayfreeW( serverctrlsW );
     controlarrayfreeW( clientctrlsW );
@@ -996,8 +981,8 @@
     ret = ldap_sasl_bind_sW( ld, dnW, mechanismW, cred, serverctrlsW, clientctrlsW, serverdata );
 
 exit:
-    strfreeW( dnW );
-    strfreeW( mechanismW );
+    free( dnW );
+    free( mechanismW );
     controlarrayfreeW( serverctrlsW );
     controlarrayfreeW( clientctrlsW );
 
@@ -1036,8 +1021,8 @@
     ret = ldap_sasl_bindW( ld, dnW, mechanismW, cred, serverctrlsW, clientctrlsW, message );
 
 exit:
-    strfreeW( dnW );
-    strfreeW( mechanismW );
+    free( dnW );
+    free( mechanismW );
     controlarrayfreeW( serverctrlsW );
     controlarrayfreeW( clientctrlsW );
 
@@ -1108,8 +1093,8 @@
   /* We can't easily map errnos to ldap_errno, thus we pass a NULL to
      the function in the hope that the server will throw an error.  */
   ret = ldap_simple_bind_sW (ld, wuser, wpass);
-  strfreeW (wpass);
-  strfreeW (wuser);
+  free (wpass);
+  free (wuser);
   return ret;
 }
 
@@ -1151,8 +1136,8 @@
                             serverctrlsW, clientctrlsW, timelimit, sizelimit, ( ULONG* )message );
 
 exit:
-    strfreeW( baseW );
-    strfreeW( filterW );
+    free( baseW );
+    free( filterW );
     strarrayfreeW( attrsW );
     controlarrayfreeW( serverctrlsW );
     controlarrayfreeW( clientctrlsW );
@@ -1188,8 +1173,8 @@
                            timeout, res );
 
 exit:
-    strfreeW( baseW );
-    strfreeW( filterW );
+    free( baseW );
+    free( filterW );
     strarrayfreeW( attrsW );
 
     return ret;
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic