Skip to content

Commit

Permalink
Merge pull request #322 from pblottiere/fix_segfault_shortcut
Browse files Browse the repository at this point in the history
Fix segmentation fault in pcpatch_transform
  • Loading branch information
pblottiere committed Sep 12, 2022
2 parents 4588b5c + 032acce commit 629241d
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions pgsql/pc_editor.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,40 +85,27 @@ Datum pcpatch_setpcid(PG_FUNCTION_ARGS)
PG_FUNCTION_INFO_V1(pcpatch_transform);
Datum pcpatch_transform(PG_FUNCTION_ARGS)
{
PCPATCH *patch, *paout;
SERIALIZED_PATCH *serpatch;
SERIALIZED_PATCH *serpa = PG_GETARG_SERPATCH_P(0);
int32 pcid = PG_GETARG_INT32(1);
float8 def = PG_GETARG_FLOAT8(2);
PCSCHEMA *oschema = pc_schema_from_pcid(serpa->pcid, fcinfo);
PCSCHEMA *nschema = pc_schema_from_pcid(pcid, fcinfo);

// fast path to setpcid if no data transformation is required

if (pc_schema_same_interpretations(oschema, nschema))
{
serpatch = pcpatch_set_schema(serpa, oschema, nschema, def);
if (!serpatch)
PG_RETURN_NULL();
PG_RETURN_POINTER(serpatch);
}
else
{
PCPATCH *patch, *paout;

patch = pc_patch_deserialize(serpa, oschema);
if (!patch)
PG_RETURN_NULL();
patch = pc_patch_deserialize(serpa, oschema);
if (!patch)
PG_RETURN_NULL();

paout = pc_patch_transform(patch, nschema, def);
paout = pc_patch_transform(patch, nschema, def);

pc_patch_free(patch);
pc_patch_free(patch);

if (!paout)
PG_RETURN_NULL();
if (!paout)
PG_RETURN_NULL();

serpatch = pc_patch_serialize(paout, NULL);
pc_patch_free(paout);
serpatch = pc_patch_serialize(paout, NULL);
pc_patch_free(paout);

PG_RETURN_POINTER(serpatch);
}
PG_RETURN_POINTER(serpatch);
}

0 comments on commit 629241d

Please sign in to comment.