diff options
Diffstat (limited to 'src/interfaces/ecpg/lib/memory.c')
| -rw-r--r-- | src/interfaces/ecpg/lib/memory.c | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/src/interfaces/ecpg/lib/memory.c b/src/interfaces/ecpg/lib/memory.c index e1bc12eef3f..5e85261332c 100644 --- a/src/interfaces/ecpg/lib/memory.c +++ b/src/interfaces/ecpg/lib/memory.c @@ -1,4 +1,4 @@ -/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/memory.c,v 1.7 2001/11/14 11:11:49 meskes Exp $ */ +/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/memory.c,v 1.8 2001/12/23 12:17:41 meskes Exp $ */ #include "postgres_fe.h" @@ -7,6 +7,12 @@ #include "ecpgerrno.h" #include "extern.h" +void +ECPGfree(void *ptr) +{ + free(ptr); +} + char * ECPGalloc(long size, int lineno) { @@ -35,3 +41,54 @@ ECPGstrdup(const char *string, int lineno) return (new); } + +/* keep a list of memory we allocated for the user */ +static struct auto_mem +{ + void *pointer; + struct auto_mem *next; +} *auto_allocs = NULL; + +void +ECPGadd_mem(void *ptr, int lineno) +{ + struct auto_mem *am = (struct auto_mem *) ECPGalloc(sizeof(struct auto_mem), lineno); + am->pointer = ptr; + am->next = auto_allocs; + auto_allocs = am; +} + +void +ECPGfree_auto_mem(void) +{ + struct auto_mem *am; + + /* free all memory we have allocated for the user */ + for (am = auto_allocs; am;) + { + struct auto_mem *act = am; + + am = am->next; + ECPGfree(act->pointer); + ECPGfree(act); + } + + auto_allocs = NULL; +} + +void +ECPGclear_auto_mem(void) +{ + struct auto_mem *am; + + /* free just our own structure */ + for (am = auto_allocs; am;) + { + struct auto_mem *act = am; + + am = am->next; + ECPGfree(act); + } + + auto_allocs = NULL; +} |
