Message ID | 1519008649-15782-5-git-send-email-me@tobin.cc (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Hi Tobin, On Mon, Feb 19, 2018 at 01:50:49PM +1100, Tobin C. Harding wrote: > +sub already_scanned > +{ > + my ($filename) = @_; > + state %seen; > + > + foreach (@once_only) { > + if (/^$filename$/) { > + if ($seen{$_} == 1) { This should be something like, if (($seen{$_} //= 0) == 1) { otherwise I get a bunch of uninitialized warnings, Use of uninitialized value in pattern match (m//) at /usr/share/perl/5.26/Math/BigInt.pm line 1199. Math::BigInt::bcmp(Math::BigInt=HASH(0x55dc2f7e4580), undef) called at /usr/share/perl/5.26/Math/BigInt.pm line 1257 Math::BigInt::beq(Math::BigInt=HASH(0x55dc2f7e4580), undef) called at /usr/share/perl/5.26/Math/BigInt.pm line 105 Math::BigInt::__ANON__(Math::BigInt=HASH(0x55dc2f7e4580), undef, 1) called at ./leaking_addresses.pl line 422 main::already_scanned("smaps") called at ./leaking_addresses.pl line 448 main::skip("/proc/1/smaps") called at ./leaking_addresses.pl line 509 main::walk("/proc", "/sys") called at ./leaking_addresses.pl line 159 Tycho
On Sun, Feb 25, 2018 at 06:09:53PM -0700, Tycho Andersen wrote: > Hi Tobin, > > On Mon, Feb 19, 2018 at 01:50:49PM +1100, Tobin C. Harding wrote: > > +sub already_scanned > > +{ > > + my ($filename) = @_; > > + state %seen; > > + > > + foreach (@once_only) { > > + if (/^$filename$/) { > > + if ($seen{$_} == 1) { > > This should be something like, > > if (($seen{$_} //= 0) == 1) { > > otherwise I get a bunch of uninitialized warnings, > > Use of uninitialized value in pattern match (m//) at /usr/share/perl/5.26/Math/BigInt.pm line 1199. > Math::BigInt::bcmp(Math::BigInt=HASH(0x55dc2f7e4580), undef) called at /usr/share/perl/5.26/Math/BigInt.pm line 1257 > Math::BigInt::beq(Math::BigInt=HASH(0x55dc2f7e4580), undef) called at /usr/share/perl/5.26/Math/BigInt.pm line 105 > Math::BigInt::__ANON__(Math::BigInt=HASH(0x55dc2f7e4580), undef, 1) called at ./leaking_addresses.pl line 422 > main::already_scanned("smaps") called at ./leaking_addresses.pl line 448 > main::skip("/proc/1/smaps") called at ./leaking_addresses.pl line 509 > main::walk("/proc", "/sys") called at ./leaking_addresses.pl line 159 > > Tycho Cool, thanks. Will fix and re-spin. Tobin
diff --git a/scripts/leaking_addresses.pl b/scripts/leaking_addresses.pl index f52e91ef7d5c..ab4e70d9efde 100755 --- a/scripts/leaking_addresses.pl +++ b/scripts/leaking_addresses.pl @@ -69,6 +69,12 @@ my @skip_any = ( 'fd', 'usbmon'); +# These files are the same format under each PID that they appear. +# We need only pass them once. +my @once_only = ( + 'smaps', + 'mb_groups'); + sub help { my ($exitcode) = @_; @@ -401,6 +407,25 @@ sub parse_dmesg close $cmd; } +sub already_scanned +{ + my ($filename) = @_; + state %seen; + + foreach (@once_only) { + if (/^$filename$/) { + if ($seen{$_} == 1) { + return 1; + } + $seen{$_} = 1; + + return 0; + } + } + + return 0; +} + # True if we should skip this path. sub skip { @@ -415,6 +440,10 @@ sub skip return 1 if (/^$filename$/); } + if (already_scanned($filename)) { + return 1; + } + return 0; }
There are files under /proc that have the same format for each PID, e.g 'smaps'. We need only scan these files a single time to verify that they are not leaking addresses. This reduces the work the script must do. Add once_only array. Signed-off-by: Tobin C. Harding <me@tobin.cc> --- scripts/leaking_addresses.pl | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)