From: Gurusamy Sarathy Date: Thu, 18 Jun 1998 16:33:01 +0000 (+0000) Subject: fix memory leaks and uninitialized memory accesses found by Purify X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=00db4c452819e776e72467584ab4e9617d012f7b;p=p5sagit%2Fp5-mst-13.2.git fix memory leaks and uninitialized memory accesses found by Purify p4raw-id: //depot/perl@1143 --- diff --git a/doio.c b/doio.c index 9d841a1..ff8384c 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 7b76edf..7705a04 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 e73152f..b6d2ca4 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 8c7d9c2..df3fbe3 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); } }