From 6f6a67807b1f562c130231373965002d3256b99a Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Sun, 7 Apr 2019 15:07:34 +0900 Subject: [PATCH] Prefer new over malloc The former cannot return NULL and will allow use of scoped pointers. --- src/common.h | 4 +--- src/common_auth.cpp | 8 +++---- src/curl.cpp | 24 +++++++++---------- src/fdcache.cpp | 14 ++++------- src/gnutls_auth.cpp | 56 ++++++++++++++------------------------------ src/nss_auth.cpp | 22 +++++------------ src/openssl_auth.cpp | 37 ++++++++--------------------- src/s3fs.cpp | 8 ++----- src/s3fs_util.cpp | 51 ++++++++++++++-------------------------- src/string_util.cpp | 8 ++----- 10 files changed, 76 insertions(+), 156 deletions(-) diff --git a/src/common.h b/src/common.h index 7b2e0bc..6a225c8 100644 --- a/src/common.h +++ b/src/common.h @@ -147,9 +147,7 @@ typedef struct xattr_value{ explicit xattr_value(unsigned char* pval = NULL, size_t len = 0) : pvalue(pval), length(len) {} ~xattr_value() { - if(pvalue){ - free(pvalue); - } + delete[] pvalue; } }XATTRVAL, *PXATTRVAL; diff --git a/src/common_auth.cpp b/src/common_auth.cpp index 23d28d5..f11bc35 100644 --- a/src/common_auth.cpp +++ b/src/common_auth.cpp @@ -44,10 +44,10 @@ string s3fs_get_content_md5(int fd) if(NULL == (base64 = s3fs_base64(md5hex, get_md5_digest_length()))){ return string(""); // ENOMEM } - free(md5hex); + delete[] md5hex; Signature = base64; - free(base64); + delete[] base64; return Signature; } @@ -62,7 +62,7 @@ string s3fs_md5sum(int fd, off_t start, ssize_t size) } std::string md5 = s3fs_hex(md5hex, digestlen); - free(md5hex); + delete[] md5hex; return md5; } @@ -81,7 +81,7 @@ string s3fs_sha256sum(int fd, off_t start, ssize_t size) for(size_t pos = 0; pos < digestlen; pos++){ snprintf(sha256 + 2 * pos, 3, "%02x", sha256hex[pos]); } - free(sha256hex); + delete[] sha256hex; return string(sha256); } diff --git a/src/curl.cpp b/src/curl.cpp index 1a1ee6d..e1f68de 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -986,7 +986,7 @@ bool S3fsCurl::PushbackSseKeys(string& onekey) if(NULL != (p_key = (char *)s3fs_decode64(onekey.c_str(), &keylength))) { raw_key = string(p_key, keylength); base64_key = onekey; - free(p_key); + delete[] p_key; } else { S3FS_PRN_ERR("Failed to convert base64 to SSE-C key %s", onekey.c_str()); return false; @@ -997,7 +997,7 @@ bool S3fsCurl::PushbackSseKeys(string& onekey) if(NULL != (pbase64_key = s3fs_base64((unsigned char*)onekey.c_str(), onekey.length()))) { raw_key = onekey; base64_key = pbase64_key; - free(pbase64_key); + delete[] pbase64_key; } else { S3FS_PRN_ERR("Failed to convert base64 from SSE-C key %s", onekey.c_str()); return false; @@ -2436,7 +2436,7 @@ string S3fsCurl::CalcSignatureV2(const string& method, const string& strMD5, con free(md); Signature = base64; - free(base64); + delete[] base64; return Signature; } @@ -2479,9 +2479,9 @@ string S3fsCurl::CalcSignature(const string& method, const string& canonical_uri s3fs_HMAC256(kDate, kDate_len, reinterpret_cast(endpoint.c_str()), endpoint.size(), &kRegion, &kRegion_len); s3fs_HMAC256(kRegion, kRegion_len, reinterpret_cast("s3"), sizeof("s3") - 1, &kService, &kService_len); s3fs_HMAC256(kService, kService_len, reinterpret_cast("aws4_request"), sizeof("aws4_request") - 1, &kSigning, &kSigning_len); - free(kDate); - free(kRegion); - free(kService); + delete[] kDate; + delete[] kRegion; + delete[] kService; const unsigned char* cRequest = reinterpret_cast(StringCQ.c_str()); unsigned int cRequest_len = StringCQ.size(); @@ -2489,7 +2489,7 @@ string S3fsCurl::CalcSignature(const string& method, const string& canonical_uri for(cnt = 0; cnt < sRequest_len; cnt++){ sprintf(&hexsRequest[cnt * 2], "%02x", sRequest[cnt]); } - free(sRequest); + delete[] sRequest; StringToSign = "AWS4-HMAC-SHA256\n"; StringToSign += date8601 + "\n"; @@ -2506,8 +2506,8 @@ string S3fsCurl::CalcSignature(const string& method, const string& canonical_uri for(cnt = 0; cnt < md_len; cnt++){ sprintf(&hexSig[cnt * 2], "%02x", md[cnt]); } - free(kSigning); - free(md); + delete[] kSigning; + delete[] md; Signature = hexSig; @@ -2578,7 +2578,7 @@ void S3fsCurl::insertV4Headers() for(cnt = 0; cnt < sRequest_len; cnt++){ sprintf(&hexsRequest[cnt * 2], "%02x", sRequest[cnt]); } - free(sRequest); + delete[] sRequest; payload_hash.assign(hexsRequest, &hexsRequest[sRequest_len * 2]); break; } @@ -3628,8 +3628,8 @@ int S3fsCurl::UploadMultipartPostSetup(const char* tpath, int part_num, const st partdata.etag = s3fs_hex(md5raw, get_md5_digest_length()); char* md5base64p = s3fs_base64(md5raw, get_md5_digest_length()); requestHeaders = curl_slist_sort_insert(requestHeaders, "Content-MD5", md5base64p); - free(md5base64p); - free(md5raw); + delete[] md5base64p; + delete[] md5raw; } // make request diff --git a/src/fdcache.cpp b/src/fdcache.cpp index ea42125..4968cc1 100644 --- a/src/fdcache.cpp +++ b/src/fdcache.cpp @@ -531,16 +531,12 @@ bool PageList::Serialize(CacheFileStat& file, bool is_output) Init(0, false); return true; } - char* ptmp; - if(NULL == (ptmp = (char*)calloc(st.st_size + 1, sizeof(char)))){ - S3FS_PRN_CRIT("could not allocate memory."); - S3FS_FUSE_EXIT(); - return false; - } + char* ptmp = new char[st.st_size + 1]; + ptmp[st.st_size] = '\0'; // read from file if(0 >= pread(file.GetFd(), ptmp, st.st_size, 0)){ S3FS_PRN_ERR("failed to read stats(%d)", errno); - free(ptmp); + delete[] ptmp; return false; } string oneline; @@ -552,7 +548,7 @@ bool PageList::Serialize(CacheFileStat& file, bool is_output) // load(size) if(!getline(ssall, oneline, '\n')){ S3FS_PRN_ERR("failed to parse stats."); - free(ptmp); + delete[] ptmp; return false; } size_t total = s3fs_strtoofft(oneline.c_str()); @@ -583,7 +579,7 @@ bool PageList::Serialize(CacheFileStat& file, bool is_output) // add new area SetPageLoadedStatus(offset, size, is_loaded); } - free(ptmp); + delete[] ptmp; if(is_err){ S3FS_PRN_ERR("failed to parse stats."); Clear(); diff --git a/src/gnutls_auth.cpp b/src/gnutls_auth.cpp index dcbea72..477cd71 100644 --- a/src/gnutls_auth.cpp +++ b/src/gnutls_auth.cpp @@ -112,9 +112,7 @@ bool s3fs_HMAC(const void* key, size_t keylen, const unsigned char* data, size_t return false; } - if(NULL == (*digest = reinterpret_cast(malloc(SHA1_DIGEST_SIZE)))){ - return false; - } + *digest = new unsigned char[SHA1_DIGEST_SIZE]; struct hmac_sha1_ctx ctx_hmac; hmac_sha1_set_key(&ctx_hmac, keylen, reinterpret_cast(key)); @@ -131,9 +129,7 @@ bool s3fs_HMAC256(const void* key, size_t keylen, const unsigned char* data, siz return false; } - if(NULL == (*digest = reinterpret_cast(malloc(SHA256_DIGEST_SIZE)))){ - return false; - } + *digest = new unsigned char[SHA256_DIGEST_SIZE]; struct hmac_sha256_ctx ctx_hmac; hmac_sha256_set_key(&ctx_hmac, keylen, reinterpret_cast(key)); @@ -155,11 +151,9 @@ bool s3fs_HMAC(const void* key, size_t keylen, const unsigned char* data, size_t if(0 == (*digestlen = gnutls_hmac_get_len(GNUTLS_MAC_SHA1))){ return false; } - if(NULL == (*digest = reinterpret_cast(malloc(*digestlen + 1)))){ - return false; - } + *digest = new unsigned char[*digestlen + 1]; if(0 > gnutls_hmac_fast(GNUTLS_MAC_SHA1, key, keylen, data, datalen, *digest)){ - free(*digest); + delete[] *digest; *digest = NULL; return false; } @@ -175,11 +169,9 @@ bool s3fs_HMAC256(const void* key, size_t keylen, const unsigned char* data, siz if(0 == (*digestlen = gnutls_hmac_get_len(GNUTLS_MAC_SHA256))){ return false; } - if(NULL == (*digest = reinterpret_cast(malloc(*digestlen + 1)))){ - return false; - } + *digest = new unsigned char[*digestlen + 1]; if(0 > gnutls_hmac_fast(GNUTLS_MAC_SHA256, key, keylen, data, datalen, *digest)){ - free(*digest); + delete[] *digest; *digest = NULL; return false; } @@ -226,13 +218,11 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, ssize_t size) md5_update(&ctx_md5, bytes, buf); memset(buf, 0, 512); } - if(NULL == (result = reinterpret_cast(malloc(get_md5_digest_length())))){ - return NULL; - } + result = new unsigned char[get_md5_digest_length()]; md5_digest(&ctx_md5, get_md5_digest_length(), result); if(-1 == lseek(fd, start, SEEK_SET)){ - free(result); + delete[] result; return NULL; } @@ -283,15 +273,12 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, ssize_t size) gcry_md_write(ctx_md5, buf, bytes); memset(buf, 0, 512); } - if(NULL == (result = reinterpret_cast(malloc(get_md5_digest_length())))){ - gcry_md_close(ctx_md5); - return NULL; - } + result = new unsigned char[get_md5_digest_length()]; memcpy(result, gcry_md_read(ctx_md5, 0), get_md5_digest_length()); gcry_md_close(ctx_md5); if(-1 == lseek(fd, start, SEEK_SET)){ - free(result); + delete[] result; return NULL; } @@ -312,9 +299,7 @@ size_t get_sha256_digest_length() bool s3fs_sha256(const unsigned char* data, unsigned int datalen, unsigned char** digest, unsigned int* digestlen) { (*digestlen) = static_cast(get_sha256_digest_length()); - if(NULL == ((*digest) = reinterpret_cast(malloc(*digestlen)))){ - return false; - } + *digest = new unsigned char[*digestlen]; struct sha256_ctx ctx_sha256; sha256_init(&ctx_sha256); @@ -353,13 +338,11 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, ssize_t size) sha256_update(&ctx_sha256, bytes, buf); memset(buf, 0, 512); } - if(NULL == (result = reinterpret_cast(malloc(get_sha256_digest_length())))){ - return NULL; - } + result = new unsigned char[get_sha256_digest_length()]; sha256_digest(&ctx_sha256, get_sha256_digest_length(), result); if(-1 == lseek(fd, start, SEEK_SET)){ - free(result); + delete[] result; return NULL; } @@ -371,15 +354,13 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, ssize_t size) bool s3fs_sha256(const unsigned char* data, unsigned int datalen, unsigned char** digest, unsigned int* digestlen) { size_t len = (*digestlen) = static_cast(get_sha256_digest_length()); - if(NULL == ((*digest) = reinterpret_cast(malloc(len)))){ - return false; - } + *digest = new unsigned char[len]; gcry_md_hd_t ctx_sha256; gcry_error_t err; if(GPG_ERR_NO_ERROR != (err = gcry_md_open(&ctx_sha256, GCRY_MD_SHA256, 0))){ S3FS_PRN_ERR("SHA256 context creation failure: %s/%s", gcry_strsource(err), gcry_strerror(err)); - free(*digest); + delete[] *digest; return false; } gcry_md_write(ctx_sha256, data, datalen); @@ -431,15 +412,12 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, ssize_t size) gcry_md_write(ctx_sha256, buf, bytes); memset(buf, 0, 512); } - if(NULL == (result = reinterpret_cast(malloc(get_sha256_digest_length())))){ - gcry_md_close(ctx_sha256); - return NULL; - } + result = new unsigned char[get_sha256_digest_length()]; memcpy(result, gcry_md_read(ctx_sha256, 0), get_sha256_digest_length()); gcry_md_close(ctx_sha256); if(-1 == lseek(fd, start, SEEK_SET)){ - free(result); + delete[] result; return NULL; } diff --git a/src/nss_auth.cpp b/src/nss_auth.cpp index a7a2fa1..90c96d6 100644 --- a/src/nss_auth.cpp +++ b/src/nss_auth.cpp @@ -127,9 +127,7 @@ static bool s3fs_HMAC_RAW(const void* key, size_t keylen, const unsigned char* d PK11_FreeSymKey(pKey); PK11_FreeSlot(Slot); - if(NULL == (*digest = reinterpret_cast(malloc(*digestlen)))){ - return false; - } + *digest = new unsigned char[*digestlen]; memcpy(*digest, tmpdigest, *digestlen); return true; @@ -192,15 +190,12 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, ssize_t size) PK11_DigestOp(md5ctx, buf, bytes); memset(buf, 0, 512); } - if(NULL == (result = reinterpret_cast(malloc(get_md5_digest_length())))){ - PK11_DestroyContext(md5ctx, PR_TRUE); - return NULL; - } + result = new unsigned char[get_md5_digest_length()]; PK11_DigestFinal(md5ctx, result, &md5outlen, get_md5_digest_length()); PK11_DestroyContext(md5ctx, PR_TRUE); if(-1 == lseek(fd, start, SEEK_SET)){ - free(result); + delete[] result; return NULL; } @@ -218,9 +213,7 @@ size_t get_sha256_digest_length() bool s3fs_sha256(const unsigned char* data, unsigned int datalen, unsigned char** digest, unsigned int* digestlen) { (*digestlen) = static_cast(get_sha256_digest_length()); - if(NULL == ((*digest) = reinterpret_cast(malloc(*digestlen)))){ - return false; - } + *digest = new unsigned char[*digestlen]; PK11Context* sha256ctx; unsigned int sha256outlen; @@ -273,15 +266,12 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, ssize_t size) PK11_DigestOp(sha256ctx, buf, bytes); memset(buf, 0, 512); } - if(NULL == (result = reinterpret_cast(malloc(get_sha256_digest_length())))){ - PK11_DestroyContext(sha256ctx, PR_TRUE); - return NULL; - } + result = new unsigned char[get_sha256_digest_length()]; PK11_DigestFinal(sha256ctx, result, &sha256outlen, get_sha256_digest_length()); PK11_DestroyContext(sha256ctx, PR_TRUE); if(-1 == lseek(fd, start, SEEK_SET)){ - free(result); + delete[] result; return NULL; } diff --git a/src/openssl_auth.cpp b/src/openssl_auth.cpp index 1ae0ae7..de5bf9c 100644 --- a/src/openssl_auth.cpp +++ b/src/openssl_auth.cpp @@ -102,12 +102,7 @@ static unsigned long s3fs_crypt_get_threadid() static struct CRYPTO_dynlock_value* s3fs_dyn_crypt_mutex(const char* file, int line) { - struct CRYPTO_dynlock_value* dyndata; - - if(NULL == (dyndata = static_cast(malloc(sizeof(struct CRYPTO_dynlock_value))))){ - S3FS_PRN_CRIT("Could not allocate memory for CRYPTO_dynlock_value"); - return NULL; - } + struct CRYPTO_dynlock_value* dyndata = new CRYPTO_dynlock_value(); pthread_mutex_init(&(dyndata->dyn_mutex), NULL); return dyndata; } @@ -127,7 +122,7 @@ static void s3fs_destroy_dyn_crypt_mutex(struct CRYPTO_dynlock_value* dyndata, c { if(dyndata){ pthread_mutex_destroy(&(dyndata->dyn_mutex)); - free(dyndata); + delete dyndata; } } @@ -140,10 +135,7 @@ bool s3fs_init_crypt_mutex() return false; } } - if(NULL == (s3fs_crypt_mutex = static_cast(malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t))))){ - S3FS_PRN_CRIT("Could not allocate memory for s3fs_crypt_mutex"); - return false; - } + s3fs_crypt_mutex = new pthread_mutex_t[CRYPTO_num_locks()]; for(int cnt = 0; cnt < CRYPTO_num_locks(); cnt++){ pthread_mutex_init(&s3fs_crypt_mutex[cnt], NULL); } @@ -174,7 +166,7 @@ bool s3fs_destroy_crypt_mutex() pthread_mutex_destroy(&s3fs_crypt_mutex[cnt]); } CRYPTO_cleanup_all_ex_data(); - free(s3fs_crypt_mutex); + delete[] s3fs_crypt_mutex; s3fs_crypt_mutex = NULL; return true; @@ -189,9 +181,7 @@ static bool s3fs_HMAC_RAW(const void* key, size_t keylen, const unsigned char* d return false; } (*digestlen) = EVP_MAX_MD_SIZE * sizeof(unsigned char); - if(NULL == ((*digest) = (unsigned char*)malloc(*digestlen))){ - return false; - } + *digest = new unsigned char[*digestlen]; if(is_sha256){ HMAC(EVP_sha256(), key, keylen, data, datalen, *digest, digestlen); }else{ @@ -257,13 +247,11 @@ unsigned char* s3fs_md5hexsum(int fd, off_t start, ssize_t size) memset(buf, 0, 512); } - if(NULL == (result = (unsigned char*)malloc(get_md5_digest_length()))){ - return NULL; - } + result = new unsigned char[get_md5_digest_length()]; MD5_Final(result, &md5ctx); if(-1 == lseek(fd, start, SEEK_SET)){ - free(result); + delete[] result; return NULL; } @@ -281,9 +269,7 @@ size_t get_sha256_digest_length() bool s3fs_sha256(const unsigned char* data, unsigned int datalen, unsigned char** digest, unsigned int* digestlen) { (*digestlen) = EVP_MAX_MD_SIZE * sizeof(unsigned char); - if(NULL == ((*digest) = reinterpret_cast(malloc(*digestlen)))){ - return false; - } + *digest = new unsigned char[*digestlen]; const EVP_MD* md = EVP_get_digestbyname("sha256"); EVP_MD_CTX* mdctx = EVP_MD_CTX_create(); @@ -335,15 +321,12 @@ unsigned char* s3fs_sha256hexsum(int fd, off_t start, ssize_t size) EVP_DigestUpdate(sha256ctx, buf, bytes); memset(buf, 0, 512); } - if(NULL == (result = (unsigned char*)malloc(get_sha256_digest_length()))){ - EVP_MD_CTX_destroy(sha256ctx); - return NULL; - } + result = new unsigned char[get_sha256_digest_length()]; EVP_DigestFinal_ex(sha256ctx, result, NULL); EVP_MD_CTX_destroy(sha256ctx); if(-1 == lseek(fd, start, SEEK_SET)){ - free(result); + delete[] result; return NULL; } return result; diff --git a/src/s3fs.cpp b/src/s3fs.cpp index a0e87f1..527a85a 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -3035,7 +3035,7 @@ static std::string build_xattrs(const xattrs_t& xattrs) char* base64val = s3fs_base64((iter->second)->pvalue, (iter->second)->length); if(base64val){ strxattrs += base64val; - free(base64val); + delete[] base64val; } } strxattrs += '\"'; @@ -3083,11 +3083,7 @@ static int set_xattrs_to_header(headers_t& meta, const char* name, const char* v PXATTRVAL pval = new XATTRVAL; pval->length = size; if(0 < size){ - if(NULL == (pval->pvalue = (unsigned char*)malloc(size))){ - delete pval; - free_xattrs(xattrs); - return -ENOMEM; - } + pval->pvalue = new unsigned char[size]; memcpy(pval->pvalue, value, size); }else{ pval->pvalue = NULL; diff --git a/src/s3fs_util.cpp b/src/s3fs_util.cpp index 5e49ea8..139073f 100644 --- a/src/s3fs_util.cpp +++ b/src/s3fs_util.cpp @@ -318,22 +318,17 @@ MVNODE *create_mvnode(const char *old_path, const char *new_path, bool is_dir, b char *p_old_path; char *p_new_path; - p = (MVNODE *) malloc(sizeof(MVNODE)); - if (p == NULL) { - printf("create_mvnode: could not allocation memory for p\n"); - S3FS_FUSE_EXIT(); - return NULL; - } + p = new MVNODE(); if(NULL == (p_old_path = strdup(old_path))){ - free(p); + delete p; printf("create_mvnode: could not allocation memory for p_old_path\n"); S3FS_FUSE_EXIT(); return NULL; } if(NULL == (p_new_path = strdup(new_path))){ - free(p); + delete p; free(p_old_path); printf("create_mvnode: could not allocation memory for p_new_path\n"); S3FS_FUSE_EXIT(); @@ -417,7 +412,7 @@ void free_mvnodes(MVNODE *head) next = my_head->next; free(my_head->old_path); free(my_head->new_path); - free(my_head); + delete my_head; } } @@ -475,33 +470,27 @@ string get_username(uid_t uid) } maxlen = res; } - if(NULL == (pbuf = (char*)malloc(sizeof(char) * maxlen))){ - S3FS_PRN_CRIT("failed to allocate memory."); - return string(""); - } + pbuf = new char[maxlen]; // get pw information while(ERANGE == (result = getpwuid_r(uid, &pwinfo, pbuf, maxlen, &ppwinfo))){ - free(pbuf); + delete[] pbuf; maxlen *= 2; - if(NULL == (pbuf = (char*)malloc(sizeof(char) * maxlen))){ - S3FS_PRN_CRIT("failed to allocate memory."); - return string(""); - } + pbuf = new char[maxlen]; } if(0 != result){ S3FS_PRN_ERR("could not get pw information(%d).", result); - free(pbuf); + delete[] pbuf; return string(""); } // check pw if(NULL == ppwinfo){ - free(pbuf); + delete[] pbuf; return string(""); } string name = SAFESTRPTR(ppwinfo->pw_name); - free(pbuf); + delete[] pbuf; return name; } @@ -531,30 +520,24 @@ int is_uid_include_group(uid_t uid, gid_t gid) } maxlen = res; } - if(NULL == (pbuf = (char*)malloc(sizeof(char) * maxlen))){ - S3FS_PRN_CRIT("failed to allocate memory."); - return -ENOMEM; - } + pbuf = new char[maxlen]; // get group information while(ERANGE == (result = getgrgid_r(gid, &ginfo, pbuf, maxlen, &pginfo))){ - free(pbuf); + delete[] pbuf; maxlen *= 2; - if(NULL == (pbuf = (char*)malloc(sizeof(char) * maxlen))){ - S3FS_PRN_CRIT("failed to allocate memory."); - return -ENOMEM; - } + pbuf = new char[maxlen]; } if(0 != result){ S3FS_PRN_ERR("could not get group information(%d).", result); - free(pbuf); + delete[] pbuf; return -result; } // check group if(NULL == pginfo){ // there is not gid in group. - free(pbuf); + delete[] pbuf; return -EINVAL; } @@ -564,11 +547,11 @@ int is_uid_include_group(uid_t uid, gid_t gid) for(ppgr_mem = pginfo->gr_mem; ppgr_mem && *ppgr_mem; ppgr_mem++){ if(username == *ppgr_mem){ // Found username in group. - free(pbuf); + delete[] pbuf; return 1; } } - free(pbuf); + delete[] pbuf; return 0; } diff --git a/src/string_util.cpp b/src/string_util.cpp index bfe547c..1849f8f 100644 --- a/src/string_util.cpp +++ b/src/string_util.cpp @@ -372,9 +372,7 @@ char* s3fs_base64(const unsigned char* input, size_t length) if(!input || 0 == length){ return NULL; } - if(NULL == (result = reinterpret_cast(malloc((((length / 3) + 1) * 4 + 1) * sizeof(char))))){ - return NULL; // ENOMEM - } + result = new char[((length / 3) + 1) * 4 + 1]; unsigned char parts[4]; size_t rpos; @@ -422,9 +420,7 @@ unsigned char* s3fs_decode64(const char* input, size_t* plength) if(!input || 0 == strlen(input) || !plength){ return NULL; } - if(NULL == (result = reinterpret_cast(malloc((strlen(input) + 1))))){ - return NULL; // ENOMEM - } + result = new unsigned char[strlen(input) + 1]; unsigned char parts[4]; size_t input_len = strlen(input);