diff options
author | Lukas Zeller <luz@synthesis.ch> | 2010-03-18 15:12:49 +0100 |
---|---|---|
committer | Lukas Zeller <luz@synthesis.ch> | 2010-03-18 15:18:15 +0100 |
commit | 7347915c7e5e0de323cd409b65787f53c04cbe24 (patch) | |
tree | c9985c007f76c214425ba6fa7e3c438afbd6bd4a | |
parent | fbc057df180bf3b01a5fca632017084a879ea121 (diff) |
sysync_b64: added b64::free() that can be called to dispose blocks allocated by b64::decode/encode
As sysync_b64 was made independent, it can't use sysync_malloc() any
more, but uses normal malloc().
However, all blocks allocated and returned by b64::encode/decode
were still returned with sysync_free(). This only did not hurt
because sysync_free was mapped to free in most (all?) builds.
Anyway, that was ugly so sysync_b64 now includes b64::free()
to clean up the situation.
This patch changes all occurrences of sysync_free() returning
blocks allocated by b64:: routines with b64::free().
-rw-r--r-- | src/DB_interfaces/odbc_db/odbcapiagent.cpp | 2 | ||||
-rwxr-xr-x | src/sysync/dataobjtype.cpp | 4 | ||||
-rw-r--r-- | src/sysync/mimedirprofile.cpp | 2 | ||||
-rwxr-xr-x | src/sysync/syncagent.cpp | 2 | ||||
-rwxr-xr-x | src/sysync/syncitemtype.cpp | 2 | ||||
-rw-r--r-- | src/sysync/syncsession.cpp | 8 | ||||
-rwxr-xr-x | src/sysync_SDK/Sources/san.cpp | 3 | ||||
-rwxr-xr-x | src/sysync_SDK/Sources/sysync_b64.cpp | 10 | ||||
-rwxr-xr-x | src/sysync_SDK/Sources/sysync_b64.h | 3 | ||||
-rwxr-xr-x | src/sysync_SDK/Sources/sysync_utils.cpp | 10 |
10 files changed, 29 insertions, 17 deletions
diff --git a/src/DB_interfaces/odbc_db/odbcapiagent.cpp b/src/DB_interfaces/odbc_db/odbcapiagent.cpp index 58aa9e8..a7f1978 100644 --- a/src/DB_interfaces/odbc_db/odbcapiagent.cpp +++ b/src/DB_interfaces/odbc_db/odbcapiagent.cpp @@ -3718,7 +3718,7 @@ bool TODBCApiAgent::CheckLogin(const char *aOriginalUserName, const char *aModif } p = b64::encode(&md5[0],16); secret = p; // save converted string - sysync_free((void *)p); + b64::free((void *)p); } col++; #ifdef SCRIPT_SUPPORT diff --git a/src/sysync/dataobjtype.cpp b/src/sysync/dataobjtype.cpp index 1273901..a45c668 100755 --- a/src/sysync/dataobjtype.cpp +++ b/src/sysync/dataobjtype.cpp @@ -503,7 +503,7 @@ void TDataObjType::generateData(TLocalEngineDS *aDatastoreP, TMultiFieldItem &aI else if (strucmp( enc.c_str(),"base64" )==0) { char* bb= b64::encode( (uInt8*)ptr,size ); v= bb; // maybe one copy operation can be avoided in future - sysync_free( bb ); // does never contain '\0' => can be treated as normal string + b64::free( bb ); // does never contain '\0' => can be treated as normal string } else if (strucmp( enc.c_str(),"quoted-printable")==0) { sysync::appendEncoded( (uInt8*)ptr,size, v, enc_quoted_printable, @@ -853,7 +853,7 @@ bool TDataObjType::parseData(const char *aText, stringSize aSize, TMultiFieldIte uInt32 oLen; uInt8* bb= b64::decode( value.c_str(), 0, &oLen ); fieldP->setAsString( (const char*)bb, oLen ); // assign the value - sysync_free ( bb ); + b64::free ( bb ); break; // already done now (blob assigned correctly } else if (strucmp( enc.c_str(),"quoted-printable")==0) { diff --git a/src/sysync/mimedirprofile.cpp b/src/sysync/mimedirprofile.cpp index 587e559..e8d1a5b 100644 --- a/src/sysync/mimedirprofile.cpp +++ b/src/sysync/mimedirprofile.cpp @@ -1923,7 +1923,7 @@ static void decodeValue( uInt32 binsz=0; uInt8 *binP = b64::decode(p, q-p, &binsz); aVal.append((const char *)binP,binsz); - sysync_free(binP); + b64::free(binP); // - continue at next char after b64 value p=q; } diff --git a/src/sysync/syncagent.cpp b/src/sysync/syncagent.cpp index ac9069e..28fc4ab 100755 --- a/src/sysync/syncagent.cpp +++ b/src/sysync/syncagent.cpp @@ -2613,7 +2613,7 @@ bool TSyncAgent::handleHeaderStatus(TStatusCommand *aStatusCmdP) uInt32 l; uInt8 *nonce = b64::decode(smlPCDataToCharP(chalmetaP->nextnonce), 0, &l); fRemoteNonce.assign((char *)nonce,l); - sysync_free(nonce); + b64::free(nonce); } // - show PDEBUGPRINTFX(DBG_PROTO,( diff --git a/src/sysync/syncitemtype.cpp b/src/sysync/syncitemtype.cpp index ba611f2..dfb665e 100755 --- a/src/sysync/syncitemtype.cpp +++ b/src/sysync/syncitemtype.cpp @@ -668,7 +668,7 @@ TSyncItem *TSyncItemType::newSyncItem( // something to decode, do it and replace original content aItemP->data->content = b64::decode(origData, origSize, (uInt32 *)&(aItemP->data->length)); // we don't need the original data any more - sysync_free((void *)origData); + b64::free((void *)origData); } } // convert payload (as a whole) from UTF16 (Unicode) to UTF-8 diff --git a/src/sysync/syncsession.cpp b/src/sysync/syncsession.cpp index 240d8e1..0be6112 100644 --- a/src/sysync/syncsession.cpp +++ b/src/sysync/syncsession.cpp @@ -3835,7 +3835,7 @@ SmlCredPtr_t TSyncSession::newCredentials(const char *aUser, const char *aPasswo // - MD5 it while adding nonce md5::Init (&context); md5::Update (&context, authdata, authdatalen); - sysync_free((void *)authdata); // return buffer allocated by b64::encode + b64::free((void *)authdata); // return buffer allocated by b64::encode // - important: add colon as nonce separator md5::Update (&context, (uInt8 *) ":", 1); // - also add nonce that will be used for checking later @@ -3878,7 +3878,7 @@ SmlCredPtr_t TSyncSession::newCredentials(const char *aUser, const char *aPasswo metinfP->format=newPCDataFormat(fRemoteRequestedAuthEnc,false); // no format if default of fmt_chr } // free buffer - if (tobefreed) sysync_free(tobefreed); + if (tobefreed) b64::free(tobefreed); // return cred or NULL if none return credP; } // TSyncSession::newCredentials @@ -4035,7 +4035,7 @@ bool TSyncSession::checkCredentials(const char *aUserName, const SmlCredPtr_t aC } } // free buffer if any - if (tobefreed) sysync_free(tobefreed); + if (tobefreed) b64::free(tobefreed); // make sure we see what config was used in the log DebugShowCfgInfo(); PDEBUGPRINTFX(DBG_HOT,( @@ -4220,7 +4220,7 @@ bool TSyncSession::getAuthBasicUserPass(const char *aBasicCreds, string &aUserna ok=true; } } - sysync_free(userpw); + b64::free(userpw); return ok; } // TSyncSession::getAuthBasicUserPass diff --git a/src/sysync_SDK/Sources/san.cpp b/src/sysync_SDK/Sources/san.cpp index 86a64c2..5b3f968 100755 --- a/src/sysync_SDK/Sources/san.cpp +++ b/src/sysync_SDK/Sources/san.cpp @@ -109,7 +109,6 @@ struct TBody { // ---- defined locally for the moment to avoid dependencies ---- -// - sysync_free replaced by free // // MD5 and B64 given string static void MD5B64_Local(const char *aString, sInt32 aLen, string &aMD5B64) @@ -128,7 +127,7 @@ static void MD5B64_Local(const char *aString, sInt32 aLen, string &aMD5B64) // assign result aMD5B64.assign(b64md5,b64md5len); // done - /*sysync_*/free(b64md5); // return buffer allocated by b64::encode + b64::free(b64md5); // return buffer allocated by b64::encode } // MD5B64_Local diff --git a/src/sysync_SDK/Sources/sysync_b64.cpp b/src/sysync_SDK/Sources/sysync_b64.cpp index e1635ad..e9cb535 100755 --- a/src/sysync_SDK/Sources/sysync_b64.cpp +++ b/src/sysync_SDK/Sources/sysync_b64.cpp @@ -21,6 +21,16 @@ static const char table [64] = { 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/' }; + +// free memory allocated with encode or decode above +void b64::free(void *mem) +{ + // we use normal malloc below, so use normal free as well + ::free(mem); +} + + + char *b64::encode (const uInt8 *instr, uInt32 len, uInt32 *outlenP, sInt16 maxLineLen, bool crLineEnd) { diff --git a/src/sysync_SDK/Sources/sysync_b64.h b/src/sysync_SDK/Sources/sysync_b64.h index d10094b..c3d9333 100755 --- a/src/sysync_SDK/Sources/sysync_b64.h +++ b/src/sysync_SDK/Sources/sysync_b64.h @@ -19,6 +19,9 @@ char *encode ( // decode B64 string to data (len=0 calculates string length automatically) uInt8 *decode(const char *instr, uInt32 len=0, uInt32 *outlenP=NULL); +// free memory allocated with encode or decode above +void free(void *mem); + } #endif /* SYSYNC_B64_H */ diff --git a/src/sysync_SDK/Sources/sysync_utils.cpp b/src/sysync_SDK/Sources/sysync_utils.cpp index c31e61f..ce55063 100755 --- a/src/sysync_SDK/Sources/sysync_utils.cpp +++ b/src/sysync_SDK/Sources/sysync_utils.cpp @@ -674,7 +674,7 @@ const char *appendDecoded( binsz=0; binP = b64::decode(aText, aSize, &binsz); aBinString.append((const char *)binP,binsz); - sysync_free(binP); + b64::free(binP); aText+=aSize; break; case enc_7bit: @@ -799,7 +799,7 @@ void appendEncoded( if (b64) { aString.append(b64,b64len); // release buffer - sysync_free(b64); + b64::free(b64); } if (aEncoding!=enc_b) { // make sure it ends with a newline for "base64" (but NOT for "b" as used in RFC2047) @@ -1896,7 +1896,7 @@ void MD5B64(const char *aString, sInt32 aLen, string &aMD5B64) // assign result aMD5B64.assign(b64md5,b64md5len); // done - sysync_free(b64md5); // return buffer allocated by b64::encode + b64::free(b64md5); // return buffer allocated by b64::encode } // MD5B64 @@ -2699,7 +2699,7 @@ SmlPcdataPtr_t newPCDataFormatted( b64len=0; b64data=b64::encode(aData, aLength, &b64len); pcdataP = newPCDataString(b64data,b64len); - sysync_free(b64data); + b64::free(b64data); return pcdataP; default: // just copy into string or opaque/C_DATA string @@ -2886,7 +2886,7 @@ SmlChalPtr_t newChallenge(TAuthTypes aAuthType, const string &aNextNonce, bool a uInt32 b64len; char *b64=b64::encode((const uInt8 *)aNextNonce.c_str(),aNextNonce.size(),&b64len); metaP->nextnonce=newPCDataString(b64,b64len); - sysync_free(b64); // return buffer allocated by b64_encode + b64::free(b64); // return buffer allocated by b64_encode } } } |