Skip to content

Commit

Permalink
Use postgres mem context in decryption (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
dAdAbird authored Aug 23, 2023
1 parent c2f6fe3 commit 19ee9a6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/encryption/enc_tuple.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define ENCRYPTION_DEBUG 1

#include "postgres.h"
#include "utils/memutils.h"

#include "encryption/enc_tuple.h"
#include "encryption/enc_aes.h"
Expand Down Expand Up @@ -76,11 +77,14 @@ static void PGTdeDecryptTupInternal2(BlockNumber bn, Page page, HeapTuple tuple,
{
char* newPtr = (char*)tuple->t_data;

// Most of the time we can't decrypt in place, so we allocate some memory... and leek it for now :(
if(allocNew)
{
newPtr = malloc(tuple->t_len);
MemoryContext oldctx = MemoryContextSwitchTo(CurTransactionContext);

newPtr = palloc(tuple->t_len);
memcpy(newPtr, tuple->t_data, tuple->t_len);

MemoryContextSwitchTo(oldctx);
}

PGTdeDecryptTupInternal(tuple->t_tableOid, bn, page, tuple->t_data, newPtr, from, to);
Expand Down

0 comments on commit 19ee9a6

Please sign in to comment.