You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@trafficserver.apache.org by "maskit (via GitHub)" <gi...@apache.org> on 2023/02/28 22:08:34 UTC

[GitHub] [trafficserver] maskit opened a new pull request, #9474: Avoid memory allocation in CryptoHash

maskit opened a new pull request, #9474:
URL: https://github.com/apache/trafficserver/pull/9474

   This partially reverts #8719. I think the memory leak is because of not calling the destructor of `CryptoContextBase`. Although use of `new` and `delete` makes the code easy to understand, we should avoid the memory allocation.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] SolidWallOfCode commented on a diff in pull request #9474: Avoid memory allocation in CryptoHash

Posted by "SolidWallOfCode (via GitHub)" <gi...@apache.org>.
SolidWallOfCode commented on code in PR #9474:
URL: https://github.com/apache/trafficserver/pull/9474#discussion_r1128285477


##########
include/tscore/CryptoHash.h:
##########
@@ -168,26 +168,23 @@ class CryptoContext : public CryptoContextBase
   }; ///< What type of hash we really are.
   static HashType Setting;
 
-  ~CryptoContext()
-  {
-    delete _base;
-    _base = nullptr;
-  }
+  ~CryptoContext() { reinterpret_cast<CryptoContextBase *>(_base)->~CryptoContextBase(); }
 
 private:
-  CryptoContextBase *_base = nullptr;
+  static size_t constexpr OBJ_SIZE = 256;

Review Comment:
   It would probably be good to have some test or debug logic that does calculate the minimum size.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] maskit commented on a diff in pull request #9474: Avoid memory allocation in CryptoHash

Posted by "maskit (via GitHub)" <gi...@apache.org>.
maskit commented on code in PR #9474:
URL: https://github.com/apache/trafficserver/pull/9474#discussion_r1128387318


##########
include/tscore/CryptoHash.h:
##########
@@ -168,26 +168,23 @@ class CryptoContext : public CryptoContextBase
   }; ///< What type of hash we really are.
   static HashType Setting;
 
-  ~CryptoContext()
-  {
-    delete _base;
-    _base = nullptr;
-  }
+  ~CryptoContext() { reinterpret_cast<CryptoContextBase *>(_base)->~CryptoContextBase(); }
 
 private:
-  CryptoContextBase *_base = nullptr;
+  static size_t constexpr OBJ_SIZE = 256;

Review Comment:
   AC_CHECK_SIZEOF? Then maybe we can do std::max. Try it if you are interested.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] maskit merged pull request #9474: Avoid memory allocation in CryptoHash

Posted by "maskit (via GitHub)" <gi...@apache.org>.
maskit merged PR #9474:
URL: https://github.com/apache/trafficserver/pull/9474


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] maskit commented on pull request #9474: Avoid memory allocation in CryptoHash

Posted by "maskit (via GitHub)" <gi...@apache.org>.
maskit commented on PR #9474:
URL: https://github.com/apache/trafficserver/pull/9474#issuecomment-1467003568

   [approve ci autest]


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] SolidWallOfCode commented on a diff in pull request #9474: Avoid memory allocation in CryptoHash

Posted by "SolidWallOfCode (via GitHub)" <gi...@apache.org>.
SolidWallOfCode commented on code in PR #9474:
URL: https://github.com/apache/trafficserver/pull/9474#discussion_r1128286539


##########
src/tscore/CryptoHash.cc:
##########
@@ -45,11 +45,13 @@ CryptoContext::CryptoContext()
   case UNSPECIFIED:
 #if TS_ENABLE_FIPS == 0
   case MD5:
-    _base = new MD5Context;
+    static_assert(OBJ_SIZE > sizeof(MD5Context));

Review Comment:
   Change these to `>=`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficserver] maskit commented on a diff in pull request #9474: Avoid memory allocation in CryptoHash

Posted by "maskit (via GitHub)" <gi...@apache.org>.
maskit commented on code in PR #9474:
URL: https://github.com/apache/trafficserver/pull/9474#discussion_r1121064750


##########
include/tscore/CryptoHash.h:
##########
@@ -168,26 +168,23 @@ class CryptoContext : public CryptoContextBase
   }; ///< What type of hash we really are.
   static HashType Setting;
 
-  ~CryptoContext()
-  {
-    delete _base;
-    _base = nullptr;
-  }
+  ~CryptoContext() { reinterpret_cast<CryptoContextBase *>(_base)->~CryptoContextBase(); }
 
 private:
-  CryptoContextBase *_base = nullptr;
+  static size_t constexpr OBJ_SIZE = 256;

Review Comment:
   I thought I may be able to calculate the minimal size but realized that  it requires including header files for SHA256 and MD5.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org