gfphoenix78 commented on code in PR #1424:
URL: https://github.com/apache/cloudberry/pull/1424#discussion_r2516580920


##########
src/backend/crypto/bufenc.c:
##########
@@ -47,16 +47,28 @@ InitializeBufferEncryption(void)
        if (!FileEncryptionEnabled)
                return;
 
+       /* 
+        * To avoid memory leaks, when the postmaster resets the cluster, 
+        * need to release the memory which was alloced at last time. 
+        */
+       if (BufEncCtx)
+       {
+               free(BufEncCtx);
+               BufEncCtx = NULL;
+       }
+       if (BufDecCtx)
+       {
+               free(BufDecCtx);
+               BufDecCtx = NULL;
+       }

Review Comment:
   ```c
   static sm4_ctx sm4_enc_ctx;
   static sm4_ctx sm4_dec_ctx;
   ...
   if (BufEncCtx && BufEncCtx != &sm4_enc_ctx) {
       pg_cipher_ctx_free(BufEncCtx);
       BufEncCtx = NULL;
   }
   if (BufDecCtx && BufDecCtx != &sm4_dec_ctx) {
       pg_cipher_ctx_free(BufDecCtx);
       BufDecCtx = NULL;
   }
   ...
   if (CheckIsSM4Method())
   {
     BufEncCtx = &sm4_enc_ctx;
     BufDecCtx = &sm4_dec_ctx;
   }
   ...
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to