mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
Remove custom memory allocation layer in pgcrypto
PX_OWN_ALLOC was intended as a way to disable the use of palloc(), and
over the time new palloc() or equivalent calls have been added like in
32984d8
, making this extra layer losing its original purpose. This
simplifies on the way some code paths to use palloc0() rather than
palloc() followed by memset(0).
Author: Daniel Gustafsson
Discussion: https://postgr.es/m/A5BFAA1A-B2E8-4CBC-895E-7B1B9475A527@yesql.se
This commit is contained in:
@ -196,8 +196,7 @@ combo_init(PX_Combo *cx, const uint8 *key, unsigned klen,
|
||||
ivs = px_cipher_iv_size(c);
|
||||
if (ivs > 0)
|
||||
{
|
||||
ivbuf = px_alloc(ivs);
|
||||
memset(ivbuf, 0, ivs);
|
||||
ivbuf = palloc0(ivs);
|
||||
if (ivlen > ivs)
|
||||
memcpy(ivbuf, iv, ivs);
|
||||
else
|
||||
@ -206,15 +205,15 @@ combo_init(PX_Combo *cx, const uint8 *key, unsigned klen,
|
||||
|
||||
if (klen > ks)
|
||||
klen = ks;
|
||||
keybuf = px_alloc(ks);
|
||||
keybuf = palloc0(ks);
|
||||
memset(keybuf, 0, ks);
|
||||
memcpy(keybuf, key, klen);
|
||||
|
||||
err = px_cipher_init(c, keybuf, klen, ivbuf);
|
||||
|
||||
if (ivbuf)
|
||||
px_free(ivbuf);
|
||||
px_free(keybuf);
|
||||
pfree(ivbuf);
|
||||
pfree(keybuf);
|
||||
|
||||
return err;
|
||||
}
|
||||
@ -238,7 +237,7 @@ combo_encrypt(PX_Combo *cx, const uint8 *data, unsigned dlen,
|
||||
/* encrypt */
|
||||
if (bs > 1)
|
||||
{
|
||||
bbuf = px_alloc(bs * 4);
|
||||
bbuf = palloc(bs * 4);
|
||||
bpos = dlen % bs;
|
||||
*rlen = dlen - bpos;
|
||||
memcpy(bbuf, data + *rlen, bpos);
|
||||
@ -283,7 +282,7 @@ combo_encrypt(PX_Combo *cx, const uint8 *data, unsigned dlen,
|
||||
}
|
||||
out:
|
||||
if (bbuf)
|
||||
px_free(bbuf);
|
||||
pfree(bbuf);
|
||||
|
||||
return err;
|
||||
}
|
||||
@ -351,7 +350,7 @@ combo_free(PX_Combo *cx)
|
||||
if (cx->cipher)
|
||||
px_cipher_free(cx->cipher);
|
||||
px_memset(cx, 0, sizeof(*cx));
|
||||
px_free(cx);
|
||||
pfree(cx);
|
||||
}
|
||||
|
||||
/* PARSER */
|
||||
@ -408,17 +407,14 @@ px_find_combo(const char *name, PX_Combo **res)
|
||||
|
||||
PX_Combo *cx;
|
||||
|
||||
cx = px_alloc(sizeof(*cx));
|
||||
memset(cx, 0, sizeof(*cx));
|
||||
|
||||
buf = px_alloc(strlen(name) + 1);
|
||||
strcpy(buf, name);
|
||||
cx = palloc0(sizeof(*cx));
|
||||
buf = pstrdup(name);
|
||||
|
||||
err = parse_cipher_name(buf, &s_cipher, &s_pad);
|
||||
if (err)
|
||||
{
|
||||
px_free(buf);
|
||||
px_free(cx);
|
||||
pfree(buf);
|
||||
pfree(cx);
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -445,7 +441,7 @@ px_find_combo(const char *name, PX_Combo **res)
|
||||
cx->decrypt_len = combo_decrypt_len;
|
||||
cx->free = combo_free;
|
||||
|
||||
px_free(buf);
|
||||
pfree(buf);
|
||||
|
||||
*res = cx;
|
||||
|
||||
@ -454,7 +450,7 @@ px_find_combo(const char *name, PX_Combo **res)
|
||||
err1:
|
||||
if (cx->cipher)
|
||||
px_cipher_free(cx->cipher);
|
||||
px_free(cx);
|
||||
px_free(buf);
|
||||
pfree(cx);
|
||||
pfree(buf);
|
||||
return PXE_NO_CIPHER;
|
||||
}
|
||||
|
Reference in New Issue
Block a user