aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Slaven <bpk@hoopajoo.net>2007-03-08 06:30:31 (GMT)
committerSteve Slaven <bpk@hoopajoo.net>2007-03-08 06:30:31 (GMT)
commit8e32cb9a8796ace1600b96e567ecbaf3a2b53c15 (patch)
tree776669bdcd29af3cc650896f139c0848589a7600
parent6f63dcd173009042b570e3da58cf16458ef849da (diff)
downloadpowwow-8e32cb9a8796ace1600b96e567ecbaf3a2b53c15.zip
powwow-8e32cb9a8796ace1600b96e567ecbaf3a2b53c15.tar.gz
powwow-8e32cb9a8796ace1600b96e567ecbaf3a2b53c15.tar.bz2
This should again fix the double-free bug that was once fixed in perlwow
-rw-r--r--ptr.c7
-rw-r--r--ptr.h6
2 files changed, 10 insertions, 3 deletions
diff --git a/ptr.c b/ptr.c
index 2c63c3e..be3a4ae 100644
--- a/ptr.c
+++ b/ptr.c
@@ -37,6 +37,7 @@ ptr ptrnew __P1 (int,max)
else if (max < 0 || max + sizeofptr < max) /* overflow! */
error = NO_MEM_ERROR;
else if ((p = (ptr)malloc(max + sizeofptr))) {
+ p->signature = PTR_SIG;
p->max = max;
ptrdata(p)[p->len = 0] = '\0';
} else
@@ -81,10 +82,12 @@ ptr ptrdup __P1 (ptr,src)
}
/* delete (free) a ptr */
-void ptrdel __P1 (ptr,p)
+void _ptrdel __P1 (ptr,p)
{
- if (p)
+ if (p && p->signature == PTR_SIG)
free((void *)p);
+ //else
+ //fprintf( stderr, "Tried to free non ptr @%x\n", p );
}
/* clear a ptr */
diff --git a/ptr.h b/ptr.h
index 06a0271..4f1654a 100644
--- a/ptr.h
+++ b/ptr.h
@@ -9,6 +9,7 @@
typedef struct s_ptr {
int len;
int max;
+ int signature;
} _ptr;
typedef _ptr * ptr;
@@ -24,7 +25,10 @@ typedef _ptr * ptr;
ptr ptrnew __P ((int max));
ptr ptrdup2 __P ((ptr src, int newmax));
ptr ptrdup __P ((ptr src));
-void ptrdel __P ((ptr p));
+
+#define PTR_SIG 91887
+#define ptrdel(x) _ptrdel(x);x=(ptr)0;
+void _ptrdel __P ((ptr p));
void ptrzero __P ((ptr p));
void ptrshrink __P ((ptr p, int len));