Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8409b60

Browse files
committed
Revert the behavior of inet/cidr functions to not unpack the arguments.
I forgot to change the functions to use the PG_GETARG_INET_PP() macro,when I changed DatumGetInetP() to unpack the datum, like Datum*P macrosusually do. Also, I screwed up the definition of the PG_GETARG_INET_PP()macro, and didn't notice because it wasn't used.This fixes the memory leak when sorting inet values, as reportedby Jochen Erwied and debugged by Andres Freund. Backpatch to 8.3, likethe previous patch that broke it.
1 parent0f44335 commit8409b60

File tree

2 files changed

+50
-50
lines changed

2 files changed

+50
-50
lines changed

‎src/backend/utils/adt/network.c

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,15 @@ network_out(inet *src, bool is_cidr)
172172
Datum
173173
inet_out(PG_FUNCTION_ARGS)
174174
{
175-
inet*src=PG_GETARG_INET_P(0);
175+
inet*src=PG_GETARG_INET_PP(0);
176176

177177
PG_RETURN_CSTRING(network_out(src, false));
178178
}
179179

180180
Datum
181181
cidr_out(PG_FUNCTION_ARGS)
182182
{
183-
inet*src=PG_GETARG_INET_P(0);
183+
inet*src=PG_GETARG_INET_PP(0);
184184

185185
PG_RETURN_CSTRING(network_out(src, true));
186186
}
@@ -299,15 +299,15 @@ network_send(inet *addr, bool is_cidr)
299299
Datum
300300
inet_send(PG_FUNCTION_ARGS)
301301
{
302-
inet*addr=PG_GETARG_INET_P(0);
302+
inet*addr=PG_GETARG_INET_PP(0);
303303

304304
PG_RETURN_BYTEA_P(network_send(addr, false));
305305
}
306306

307307
Datum
308308
cidr_send(PG_FUNCTION_ARGS)
309309
{
310-
inet*addr=PG_GETARG_INET_P(0);
310+
inet*addr=PG_GETARG_INET_PP(0);
311311

312312
PG_RETURN_BYTEA_P(network_send(addr, true));
313313
}
@@ -316,7 +316,7 @@ cidr_send(PG_FUNCTION_ARGS)
316316
Datum
317317
inet_to_cidr(PG_FUNCTION_ARGS)
318318
{
319-
inet*src=PG_GETARG_INET_P(0);
319+
inet*src=PG_GETARG_INET_PP(0);
320320
inet*dst;
321321
intbits;
322322
intbyte;
@@ -357,7 +357,7 @@ inet_to_cidr(PG_FUNCTION_ARGS)
357357
Datum
358358
inet_set_masklen(PG_FUNCTION_ARGS)
359359
{
360-
inet*src=PG_GETARG_INET_P(0);
360+
inet*src=PG_GETARG_INET_PP(0);
361361
intbits=PG_GETARG_INT32(1);
362362
inet*dst;
363363

@@ -381,7 +381,7 @@ inet_set_masklen(PG_FUNCTION_ARGS)
381381
Datum
382382
cidr_set_masklen(PG_FUNCTION_ARGS)
383383
{
384-
inet*src=PG_GETARG_INET_P(0);
384+
inet*src=PG_GETARG_INET_PP(0);
385385
intbits=PG_GETARG_INT32(1);
386386
inet*dst;
387387
intbyte;
@@ -457,8 +457,8 @@ network_cmp_internal(inet *a1, inet *a2)
457457
Datum
458458
network_cmp(PG_FUNCTION_ARGS)
459459
{
460-
inet*a1=PG_GETARG_INET_P(0);
461-
inet*a2=PG_GETARG_INET_P(1);
460+
inet*a1=PG_GETARG_INET_PP(0);
461+
inet*a2=PG_GETARG_INET_PP(1);
462462

463463
PG_RETURN_INT32(network_cmp_internal(a1,a2));
464464
}
@@ -469,53 +469,53 @@ network_cmp(PG_FUNCTION_ARGS)
469469
Datum
470470
network_lt(PG_FUNCTION_ARGS)
471471
{
472-
inet*a1=PG_GETARG_INET_P(0);
473-
inet*a2=PG_GETARG_INET_P(1);
472+
inet*a1=PG_GETARG_INET_PP(0);
473+
inet*a2=PG_GETARG_INET_PP(1);
474474

475475
PG_RETURN_BOOL(network_cmp_internal(a1,a2)<0);
476476
}
477477

478478
Datum
479479
network_le(PG_FUNCTION_ARGS)
480480
{
481-
inet*a1=PG_GETARG_INET_P(0);
482-
inet*a2=PG_GETARG_INET_P(1);
481+
inet*a1=PG_GETARG_INET_PP(0);
482+
inet*a2=PG_GETARG_INET_PP(1);
483483

484484
PG_RETURN_BOOL(network_cmp_internal(a1,a2) <=0);
485485
}
486486

487487
Datum
488488
network_eq(PG_FUNCTION_ARGS)
489489
{
490-
inet*a1=PG_GETARG_INET_P(0);
491-
inet*a2=PG_GETARG_INET_P(1);
490+
inet*a1=PG_GETARG_INET_PP(0);
491+
inet*a2=PG_GETARG_INET_PP(1);
492492

493493
PG_RETURN_BOOL(network_cmp_internal(a1,a2)==0);
494494
}
495495

496496
Datum
497497
network_ge(PG_FUNCTION_ARGS)
498498
{
499-
inet*a1=PG_GETARG_INET_P(0);
500-
inet*a2=PG_GETARG_INET_P(1);
499+
inet*a1=PG_GETARG_INET_PP(0);
500+
inet*a2=PG_GETARG_INET_PP(1);
501501

502502
PG_RETURN_BOOL(network_cmp_internal(a1,a2) >=0);
503503
}
504504

505505
Datum
506506
network_gt(PG_FUNCTION_ARGS)
507507
{
508-
inet*a1=PG_GETARG_INET_P(0);
509-
inet*a2=PG_GETARG_INET_P(1);
508+
inet*a1=PG_GETARG_INET_PP(0);
509+
inet*a2=PG_GETARG_INET_PP(1);
510510

511511
PG_RETURN_BOOL(network_cmp_internal(a1,a2)>0);
512512
}
513513

514514
Datum
515515
network_ne(PG_FUNCTION_ARGS)
516516
{
517-
inet*a1=PG_GETARG_INET_P(0);
518-
inet*a2=PG_GETARG_INET_P(1);
517+
inet*a1=PG_GETARG_INET_PP(0);
518+
inet*a2=PG_GETARG_INET_PP(1);
519519

520520
PG_RETURN_BOOL(network_cmp_internal(a1,a2)!=0);
521521
}
@@ -526,7 +526,7 @@ network_ne(PG_FUNCTION_ARGS)
526526
Datum
527527
hashinet(PG_FUNCTION_ARGS)
528528
{
529-
inet*addr=PG_GETARG_INET_P(0);
529+
inet*addr=PG_GETARG_INET_PP(0);
530530
intaddrsize=ip_addrsize(addr);
531531

532532
/* XXX this assumes there are no pad bytes in the data structure */
@@ -539,8 +539,8 @@ hashinet(PG_FUNCTION_ARGS)
539539
Datum
540540
network_sub(PG_FUNCTION_ARGS)
541541
{
542-
inet*a1=PG_GETARG_INET_P(0);
543-
inet*a2=PG_GETARG_INET_P(1);
542+
inet*a1=PG_GETARG_INET_PP(0);
543+
inet*a2=PG_GETARG_INET_PP(1);
544544

545545
if (ip_family(a1)==ip_family(a2))
546546
{
@@ -554,8 +554,8 @@ network_sub(PG_FUNCTION_ARGS)
554554
Datum
555555
network_subeq(PG_FUNCTION_ARGS)
556556
{
557-
inet*a1=PG_GETARG_INET_P(0);
558-
inet*a2=PG_GETARG_INET_P(1);
557+
inet*a1=PG_GETARG_INET_PP(0);
558+
inet*a2=PG_GETARG_INET_PP(1);
559559

560560
if (ip_family(a1)==ip_family(a2))
561561
{
@@ -569,8 +569,8 @@ network_subeq(PG_FUNCTION_ARGS)
569569
Datum
570570
network_sup(PG_FUNCTION_ARGS)
571571
{
572-
inet*a1=PG_GETARG_INET_P(0);
573-
inet*a2=PG_GETARG_INET_P(1);
572+
inet*a1=PG_GETARG_INET_PP(0);
573+
inet*a2=PG_GETARG_INET_PP(1);
574574

575575
if (ip_family(a1)==ip_family(a2))
576576
{
@@ -584,8 +584,8 @@ network_sup(PG_FUNCTION_ARGS)
584584
Datum
585585
network_supeq(PG_FUNCTION_ARGS)
586586
{
587-
inet*a1=PG_GETARG_INET_P(0);
588-
inet*a2=PG_GETARG_INET_P(1);
587+
inet*a1=PG_GETARG_INET_PP(0);
588+
inet*a2=PG_GETARG_INET_PP(1);
589589

590590
if (ip_family(a1)==ip_family(a2))
591591
{
@@ -602,7 +602,7 @@ network_supeq(PG_FUNCTION_ARGS)
602602
Datum
603603
network_host(PG_FUNCTION_ARGS)
604604
{
605-
inet*ip=PG_GETARG_INET_P(0);
605+
inet*ip=PG_GETARG_INET_PP(0);
606606
char*ptr;
607607
chartmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
608608

@@ -628,7 +628,7 @@ network_host(PG_FUNCTION_ARGS)
628628
Datum
629629
network_show(PG_FUNCTION_ARGS)
630630
{
631-
inet*ip=PG_GETARG_INET_P(0);
631+
inet*ip=PG_GETARG_INET_PP(0);
632632
intlen;
633633
chartmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
634634

@@ -651,7 +651,7 @@ network_show(PG_FUNCTION_ARGS)
651651
Datum
652652
inet_abbrev(PG_FUNCTION_ARGS)
653653
{
654-
inet*ip=PG_GETARG_INET_P(0);
654+
inet*ip=PG_GETARG_INET_PP(0);
655655
char*dst;
656656
chartmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
657657

@@ -669,7 +669,7 @@ inet_abbrev(PG_FUNCTION_ARGS)
669669
Datum
670670
cidr_abbrev(PG_FUNCTION_ARGS)
671671
{
672-
inet*ip=PG_GETARG_INET_P(0);
672+
inet*ip=PG_GETARG_INET_PP(0);
673673
char*dst;
674674
chartmp[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:255.255.255.255/128")];
675675

@@ -687,15 +687,15 @@ cidr_abbrev(PG_FUNCTION_ARGS)
687687
Datum
688688
network_masklen(PG_FUNCTION_ARGS)
689689
{
690-
inet*ip=PG_GETARG_INET_P(0);
690+
inet*ip=PG_GETARG_INET_PP(0);
691691

692692
PG_RETURN_INT32(ip_bits(ip));
693693
}
694694

695695
Datum
696696
network_family(PG_FUNCTION_ARGS)
697697
{
698-
inet*ip=PG_GETARG_INET_P(0);
698+
inet*ip=PG_GETARG_INET_PP(0);
699699

700700
switch (ip_family(ip))
701701
{
@@ -714,7 +714,7 @@ network_family(PG_FUNCTION_ARGS)
714714
Datum
715715
network_broadcast(PG_FUNCTION_ARGS)
716716
{
717-
inet*ip=PG_GETARG_INET_P(0);
717+
inet*ip=PG_GETARG_INET_PP(0);
718718
inet*dst;
719719
intbyte;
720720
intbits;
@@ -763,7 +763,7 @@ network_broadcast(PG_FUNCTION_ARGS)
763763
Datum
764764
network_network(PG_FUNCTION_ARGS)
765765
{
766-
inet*ip=PG_GETARG_INET_P(0);
766+
inet*ip=PG_GETARG_INET_PP(0);
767767
inet*dst;
768768
intbyte;
769769
intbits;
@@ -807,7 +807,7 @@ network_network(PG_FUNCTION_ARGS)
807807
Datum
808808
network_netmask(PG_FUNCTION_ARGS)
809809
{
810-
inet*ip=PG_GETARG_INET_P(0);
810+
inet*ip=PG_GETARG_INET_PP(0);
811811
inet*dst;
812812
intbyte;
813813
intbits;
@@ -849,7 +849,7 @@ network_netmask(PG_FUNCTION_ARGS)
849849
Datum
850850
network_hostmask(PG_FUNCTION_ARGS)
851851
{
852-
inet*ip=PG_GETARG_INET_P(0);
852+
inet*ip=PG_GETARG_INET_PP(0);
853853
inet*dst;
854854
intbyte;
855855
intbits;
@@ -1218,7 +1218,7 @@ inet_server_port(PG_FUNCTION_ARGS)
12181218
Datum
12191219
inetnot(PG_FUNCTION_ARGS)
12201220
{
1221-
inet*ip=PG_GETARG_INET_P(0);
1221+
inet*ip=PG_GETARG_INET_PP(0);
12221222
inet*dst;
12231223

12241224
dst= (inet*)palloc0(sizeof(inet));
@@ -1243,8 +1243,8 @@ inetnot(PG_FUNCTION_ARGS)
12431243
Datum
12441244
inetand(PG_FUNCTION_ARGS)
12451245
{
1246-
inet*ip=PG_GETARG_INET_P(0);
1247-
inet*ip2=PG_GETARG_INET_P(1);
1246+
inet*ip=PG_GETARG_INET_PP(0);
1247+
inet*ip2=PG_GETARG_INET_PP(1);
12481248
inet*dst;
12491249

12501250
dst= (inet*)palloc0(sizeof(inet));
@@ -1275,8 +1275,8 @@ inetand(PG_FUNCTION_ARGS)
12751275
Datum
12761276
inetor(PG_FUNCTION_ARGS)
12771277
{
1278-
inet*ip=PG_GETARG_INET_P(0);
1279-
inet*ip2=PG_GETARG_INET_P(1);
1278+
inet*ip=PG_GETARG_INET_PP(0);
1279+
inet*ip2=PG_GETARG_INET_PP(1);
12801280
inet*dst;
12811281

12821282
dst= (inet*)palloc0(sizeof(inet));
@@ -1359,7 +1359,7 @@ internal_inetpl(inet *ip, int64 addend)
13591359
Datum
13601360
inetpl(PG_FUNCTION_ARGS)
13611361
{
1362-
inet*ip=PG_GETARG_INET_P(0);
1362+
inet*ip=PG_GETARG_INET_PP(0);
13631363
int64addend=PG_GETARG_INT64(1);
13641364

13651365
PG_RETURN_INET_P(internal_inetpl(ip,addend));
@@ -1369,7 +1369,7 @@ inetpl(PG_FUNCTION_ARGS)
13691369
Datum
13701370
inetmi_int8(PG_FUNCTION_ARGS)
13711371
{
1372-
inet*ip=PG_GETARG_INET_P(0);
1372+
inet*ip=PG_GETARG_INET_PP(0);
13731373
int64addend=PG_GETARG_INT64(1);
13741374

13751375
PG_RETURN_INET_P(internal_inetpl(ip,-addend));
@@ -1379,8 +1379,8 @@ inetmi_int8(PG_FUNCTION_ARGS)
13791379
Datum
13801380
inetmi(PG_FUNCTION_ARGS)
13811381
{
1382-
inet*ip=PG_GETARG_INET_P(0);
1383-
inet*ip2=PG_GETARG_INET_P(1);
1382+
inet*ip=PG_GETARG_INET_PP(0);
1383+
inet*ip2=PG_GETARG_INET_PP(1);
13841384
int64res=0;
13851385

13861386
if (ip_family(ip)!=ip_family(ip2))

‎src/include/utils/inet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ typedef struct macaddr
7474
#defineDatumGetInetPP(X)((inet *) PG_DETOAST_DATUM_PACKED(X))
7575
#defineInetPGetDatum(X)PointerGetDatum(X)
7676
#definePG_GETARG_INET_P(n) DatumGetInetP(PG_GETARG_DATUM(n))
77-
#definePG_GETARG_INET_PP(n)DatumGetInetP(PG_GETARG_DATUM_PACKED(n))
77+
#definePG_GETARG_INET_PP(n)DatumGetInetPP(PG_GETARG_DATUM(n))
7878
#definePG_RETURN_INET_P(x) return InetPGetDatum(x)
7979
/* macaddr is a fixed-length pass-by-reference datatype */
8080
#defineDatumGetMacaddrP(X) ((macaddr *) DatumGetPointer(X))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp