This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
In strftime(), save a malloc()/free() by using sv_usepvn_flags().
authorNicholas Clark <nick@ccl4.org>
Thu, 15 Oct 2009 15:26:51 +0000 (16:26 +0100)
committerNicholas Clark <nick@ccl4.org>
Thu, 15 Oct 2009 16:12:59 +0000 (17:12 +0100)
ext/POSIX/POSIX.xs

index b3a64a7..8572367 100644 (file)
@@ -1795,8 +1795,12 @@ strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)
        {
            char *buf = my_strftime(SvPV_nolen(fmt), sec, min, hour, mday, mon, year, wday, yday, isdst);
            if (buf) {
        {
            char *buf = my_strftime(SvPV_nolen(fmt), sec, min, hour, mday, mon, year, wday, yday, isdst);
            if (buf) {
-               ST(0) = newSVpvn_flags(buf, strlen(buf), SVs_TEMP | SvUTF8(fmt));
-               Safefree(buf);
+               SV *const sv = sv_newmortal();
+               sv_usepvn_flags(sv, buf, strlen(buf), SV_HAS_TRAILING_NUL);
+               if (SvUTF8(fmt)) {
+                   SvUTF8_on(sv);
+               }
+               ST(0) = sv;
            }
        }
 
            }
        }