summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>1998-06-18 16:33:01 +0000
committerGurusamy Sarathy <gsar@cpan.org>1998-06-18 16:33:01 +0000
commit00db4c452819e776e72467584ab4e9617d012f7b (patch)
treea0211b478efd413d7b381a4a612d15e1a33036d8
parent3b818b81e61465ce5ae6f7c21e6ca3b83d30216e (diff)
downloadperl-00db4c452819e776e72467584ab4e9617d012f7b.tar.gz
fix memory leaks and uninitialized memory accesses found by Purify
p4raw-id: //depot/perl@1143
-rw-r--r--doio.c2
-rw-r--r--perl.c17
-rw-r--r--regexec.c2
-rw-r--r--sv.c18
4 files changed, 23 insertions, 16 deletions
diff --git a/doio.c b/doio.c
index 9d841a195c..ff8384c331 100644
--- a/doio.c
+++ b/doio.c
@@ -258,7 +258,7 @@ do_open(GV *gv, register char *name, I32 len, int as_raw, int rawmode, int rawpe
else
fp = PerlIO_open(name,mode);
}
- else if (name[len-1] == '|') {
+ else if (len > 1 && name[len-1] == '|') {
name[--len] = '\0';
while (len && isSPACE(name[len-1]))
name[--len] = '\0';
diff --git a/perl.c b/perl.c
index 7b76edf996..7705a04a9f 100644
--- a/perl.c
+++ b/perl.c
@@ -551,8 +551,11 @@ perl_destruct(register PerlInterpreter *sv_interp)
/* No SVs have survived, need to clean out */
linestr = NULL;
pidstatus = Nullhv;
- if (origfilename)
- Safefree(origfilename);
+ Safefree(origfilename);
+ Safefree(archpat_auto);
+ Safefree(reg_start_tmp);
+ Safefree(HeKEY_hek(&hv_fetch_ent_mh));
+ Safefree(op_mask);
nuke_stacks();
hints = 0; /* Reset hints. Should hints be per-interpreter ? */
@@ -2351,6 +2354,12 @@ nuke_stacks(void)
curstackinfo = p;
}
Safefree(tmps_stack);
+ /* XXX refcount interpreters to determine when to free global data
+ Safefree(markstack);
+ Safefree(scopestack);
+ Safefree(savestack);
+ Safefree(retstack);
+ */
DEBUG( {
Safefree(debname);
Safefree(debdelim);
@@ -2578,7 +2587,7 @@ incpush(char *p, int addsubdirs)
return;
if (addsubdirs) {
- subdir = NEWSV(55,0);
+ subdir = sv_newmortal();
if (!archpat_auto) {
STRLEN len = (sizeof(ARCHNAME) + strlen(patchlevel)
+ sizeof("//auto"));
@@ -2654,8 +2663,6 @@ incpush(char *p, int addsubdirs)
/* finally push this lib directory on the end of @INC */
av_push(GvAVn(incgv), libdir);
}
-
- SvREFCNT_dec(subdir);
}
#ifdef USE_THREADS
diff --git a/regexec.c b/regexec.c
index e73152f404..b6d2ca4ff4 100644
--- a/regexec.c
+++ b/regexec.c
@@ -1258,7 +1258,7 @@ regmatch(regnode *prog)
break;
case CURLYM:
{
- I32 l;
+ I32 l = 0;
CHECKPOINT lastcp;
/* We suppose that the next guy does not need
diff --git a/sv.c b/sv.c
index 8c7d9c2a3b..df3fbe3aeb 100644
--- a/sv.c
+++ b/sv.c
@@ -96,17 +96,17 @@ typedef void (*SVFUNC) _((SV*));
} while (0)
static SV **registry;
-static I32 regsize;
+static I32 registry_size;
#define REGHASH(sv,size) ((((U32)(sv)) >> 2) % (size))
#define REG_REPLACE(sv,a,b) \
do { \
void* p = sv->sv_any; \
- I32 h = REGHASH(sv, regsize); \
+ I32 h = REGHASH(sv, registry_size); \
I32 i = h; \
while (registry[i] != (a)) { \
- if (++i >= regsize) \
+ if (++i >= registry_size) \
i = 0; \
if (i == h) \
die("SV registry bug"); \
@@ -121,13 +121,13 @@ static void
reg_add(sv)
SV* sv;
{
- if (sv_count >= (regsize >> 1))
+ if (sv_count >= (registry_size >> 1))
{
SV **oldreg = registry;
- I32 oldsize = regsize;
+ I32 oldsize = registry_size;
- regsize = regsize ? ((regsize << 2) + 1) : 2037;
- Newz(707, registry, regsize, SV*);
+ registry_size = registry_size ? ((registry_size << 2) + 1) : 2037;
+ Newz(707, registry, registry_size, SV*);
if (oldreg) {
I32 i;
@@ -159,9 +159,9 @@ SVFUNC f;
{
I32 i;
- for (i = 0; i < regsize; ++i) {
+ for (i = 0; i < registry_size; ++i) {
SV* sv = registry[i];
- if (sv)
+ if (sv && SvTYPE(sv) != SVTYPEMASK)
(*f)(sv);
}
}