Re: SV leak?
Vincent Pit [Thu, 3 Jan 2008 19:26:05 +0000 (20:26 +0100)]
Message-ID: <477D28BD.5060801@profvince.com>

Mortalize SVs that are being pushed on the stack.
Try to use specialized macros for pushing mortals.

p4raw-id: //depot/perl@32822

ext/B/B.xs
ext/Win32/Win32.xs
mg.c
os2/os2.c
pp_sys.c
win32/wince.c

index 8f22122..30635f7 100644 (file)
@@ -2011,7 +2011,7 @@ HvARRAY(hv)
            (void)hv_iterinit(hv);
            EXTEND(sp, HvKEYS(hv) * 2);
            while ((sv = hv_iternextsv(hv, &key, &len))) {
-               PUSHs(newSVpvn(key, len));
+               mPUSHp(key, len);
                PUSHs(make_sv_object(aTHX_ sv_newmortal(), sv));
            }
        }
index 9d0142d..d6c8063 100644 (file)
@@ -1245,17 +1245,17 @@ XS(w32_GetOSVersion)
     if (GIMME_V == G_SCALAR) {
         XSRETURN_IV(g_osver.dwPlatformId);
     }
-    XPUSHs(newSVpvn(g_osver.szCSDVersion, strlen(g_osver.szCSDVersion)));
+    mXPUSHp(g_osver.szCSDVersion, strlen(g_osver.szCSDVersion));
 
-    XPUSHs(newSViv(g_osver.dwMajorVersion));
-    XPUSHs(newSViv(g_osver.dwMinorVersion));
-    XPUSHs(newSViv(g_osver.dwBuildNumber));
-    XPUSHs(newSViv(g_osver.dwPlatformId));
+    mXPUSHi(g_osver.dwMajorVersion);
+    mXPUSHi(g_osver.dwMinorVersion);
+    mXPUSHi(g_osver.dwBuildNumber);
+    mXPUSHi(g_osver.dwPlatformId);
     if (g_osver_ex) {
-        XPUSHs(newSViv(g_osver.wServicePackMajor));
-        XPUSHs(newSViv(g_osver.wServicePackMinor));
-        XPUSHs(newSViv(g_osver.wSuiteMask));
-        XPUSHs(newSViv(g_osver.wProductType));
+        mXPUSHi(g_osver.wServicePackMajor);
+        mXPUSHi(g_osver.wServicePackMinor);
+        mXPUSHi(g_osver.wSuiteMask);
+        mXPUSHi(g_osver.wProductType);
     }
     PUTBACK;
 }
diff --git a/mg.c b/mg.c
index d7c68c5..f1acc39 100644 (file)
--- a/mg.c
+++ b/mg.c
@@ -2829,7 +2829,7 @@ Perl_sighandler(int sig)
 #endif
                   EXTEND(SP, 2);
                   PUSHs((SV*)rv);
-                  PUSHs(newSVpvn((char *)sip, sizeof(*sip)));
+                  mPUSHp((char *)sip, sizeof(*sip));
              }
 
         }
index 5c05df5..4ebdd50 100644 (file)
--- a/os2/os2.c
+++ b/os2/os2.c
@@ -4360,10 +4360,10 @@ XS(XS_OS2_pipeCntl)
                                      &PipeState), "DosPeekNPipe() for state");
            if (state) {
                EXTEND(SP, 3);
-               PUSHs(newSVuv(PipeState));
+               mPUSHu(PipeState);
                /*   Bytes (available/in-message) */
-               PUSHs(newSViv(BytesAvail.cbpipe));
-               PUSHs(newSViv(BytesAvail.cbmessage));
+               mPUSHi(BytesAvail.cbpipe);
+               mPUSHi(BytesAvail.cbmessage);
                XSRETURN(3);
            } else if (info) {
                /* L S S C C C/Z*
@@ -4390,12 +4390,12 @@ XS(XS_OS2_pipeCntl)
                else
                    size = strlen(b.pInfo.szName);
                EXTEND(SP, 6);
-               PUSHs(newSVpvn(b.pInfo.szName, size));
-               PUSHs(newSVuv(b.id));
-               PUSHs(newSViv(b.pInfo.cbOut));
-               PUSHs(newSViv(b.pInfo.cbIn));
-               PUSHs(newSViv(b.pInfo.cbMaxInst));
-               PUSHs(newSViv(b.pInfo.cbCurInst));
+               mPUSHp(b.pInfo.szName, size);
+               mPUSHu(b.id);
+               mPUSHi(b.pInfo.cbOut);
+               mPUSHi(b.pInfo.cbIn);
+               mPUSHi(b.pInfo.cbMaxInst);
+               mPUSHi(b.pInfo.cbCurInst);
                XSRETURN(6);
            } else if (BytesAvail.cbpipe == 0) {
                XSRETURN_NO;
index 3ee3384..66ca0fb 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -4701,7 +4701,7 @@ PP(pp_ghostent)
        }
 #else
        if (hent->h_addr)
-           PUSHs(newSVpvn(hent->h_addr, len));
+           mPUSHp(hent->h_addr, len);
        else
            PUSHs(sv_mortalcopy(&PL_sv_no));
 #endif /* h_addr */
index 60a6809..103a665 100644 (file)
@@ -2440,12 +2440,12 @@ XS(w32_GetOSVersion)
     if (!XCEGetVersionExA(&osver)) {
       XSRETURN_EMPTY;
     }
-    XPUSHs(newSVpvn(osver.szCSDVersion, strlen(osver.szCSDVersion)));
-    XPUSHs(newSViv(osver.dwMajorVersion));
-    XPUSHs(newSViv(osver.dwMinorVersion));
-    XPUSHs(newSViv(osver.dwBuildNumber));
+    mXPUSHp(osver.szCSDVersion, strlen(osver.szCSDVersion));
+    mXPUSHi(osver.dwMajorVersion);
+    mXPUSHi(osver.dwMinorVersion);
+    mXPUSHi(osver.dwBuildNumber);
     /* WINCE = 3 */
-    XPUSHs(newSViv(osver.dwPlatformId));
+    mXPUSHi(osver.dwPlatformId);
     PUTBACK;
 }
 
@@ -2554,15 +2554,15 @@ XS(w32_GetPowerStatus)
       XSRETURN_EMPTY;
     }
 
-  XPUSHs(newSViv(sps.ACLineStatus));
-  XPUSHs(newSViv(sps.BatteryFlag));
-  XPUSHs(newSViv(sps.BatteryLifePercent));
-  XPUSHs(newSViv(sps.BatteryLifeTime));
-  XPUSHs(newSViv(sps.BatteryFullLifeTime));
-  XPUSHs(newSViv(sps.BackupBatteryFlag));
-  XPUSHs(newSViv(sps.BackupBatteryLifePercent));
-  XPUSHs(newSViv(sps.BackupBatteryLifeTime));
-  XPUSHs(newSViv(sps.BackupBatteryFullLifeTime));
+  mXPUSHi(sps.ACLineStatus);
+  mXPUSHi(sps.BatteryFlag);
+  mXPUSHi(sps.BatteryLifePercent);
+  mXPUSHi(sps.BatteryLifeTime);
+  mXPUSHi(sps.BatteryFullLifeTime);
+  mXPUSHi(sps.BackupBatteryFlag);
+  mXPUSHi(sps.BackupBatteryLifePercent);
+  mXPUSHi(sps.BackupBatteryLifeTime);
+  mXPUSHi(sps.BackupBatteryFullLifeTime);
 
   PUTBACK;
 }