Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8f65c02

Browse files
committed
Remove the currently unused FRONTEND case in dllist.c. This allows the usage
of palloc instead of malloc, which means a list can be freed simply by deleting the memory context that contains it.
1 parent bb8998a commit 8f65c02

File tree

1 file changed

+8
-36
lines changed

1 file changed

+8
-36
lines changed

src/backend/lib/dllist.c

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,11 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/lib/dllist.c,v 1.34 2007/01/05 22:19:29 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/lib/dllist.c,v 1.35 2007/03/22 18:57:52 alvherre Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
16-
17-
/* can be used in frontend or backend */
18-
#ifdef FRONTEND
19-
#include "postgres_fe.h"
20-
/* No assert checks in frontend ... */
21-
#define Assert(condition)
22-
#else
2316
#include "postgres.h"
24-
#endif
2517

2618
#include "lib/dllist.h"
2719

@@ -31,18 +23,8 @@ DLNewList(void)
3123
{
3224
Dllist *l;
3325

34-
l = (Dllist *) malloc(sizeof(Dllist));
35-
if (l == NULL)
36-
{
37-
#ifdef FRONTEND
38-
fprintf(stderr, "memory exhausted in DLNewList\n");
39-
exit(1);
40-
#else
41-
ereport(ERROR,
42-
(errcode(ERRCODE_OUT_OF_MEMORY),
43-
errmsg("out of memory")));
44-
#endif
45-
}
26+
l = (Dllist *) palloc(sizeof(Dllist));
27+
4628
l->dll_head = NULL;
4729
l->dll_tail = NULL;
4830

@@ -66,28 +48,18 @@ DLFreeList(Dllist *list)
6648
Dlelem *curr;
6749

6850
while ((curr = DLRemHead(list)) != NULL)
69-
free(curr);
51+
pfree(curr);
7052

71-
free(list);
53+
pfree(list);
7254
}
7355

7456
Dlelem *
7557
DLNewElem(void *val)
7658
{
7759
Dlelem *e;
7860

79-
e = (Dlelem *) malloc(sizeof(Dlelem));
80-
if (e == NULL)
81-
{
82-
#ifdef FRONTEND
83-
fprintf(stderr, "memory exhausted in DLNewElem\n");
84-
exit(1);
85-
#else
86-
ereport(ERROR,
87-
(errcode(ERRCODE_OUT_OF_MEMORY),
88-
errmsg("out of memory")));
89-
#endif
90-
}
61+
e = (Dlelem *) palloc(sizeof(Dlelem));
62+
9163
e->dle_next = NULL;
9264
e->dle_prev = NULL;
9365
e->dle_val = val;
@@ -107,7 +79,7 @@ DLInitElem(Dlelem *e, void *val)
10779
void
10880
DLFreeElem(Dlelem *e)
10981
{
110-
free(e);
82+
pfree(e);
11183
}
11284

11385
void

0 commit comments

Comments
 (0)