File: leaktrace.t

package info (click to toggle)
libcpanel-json-xs-perl 4.40-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,876 kB
  • sloc: perl: 1,165; makefile: 8
file content (44 lines) | stat: -rw-r--r-- 1,124 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!perl -w
# note that does not catch the leaking XS context cxt->sv_json #19
# even valgrind does not catch it

use strict;
use constant HAS_LEAKTRACE => eval{ require Test::LeakTrace };
use Test::More HAS_LEAKTRACE ? (tests => 4) : (skip_all => 'require Test::LeakTrace');
use Test::LeakTrace;

use Cpanel::JSON::XS;

leaks_cmp_ok{
  my $js = Cpanel::JSON::XS->new->convert_blessed->allow_tags->allow_nonref;
  $js->decode('"\ud801\udc02' . "\x{10204}\"");
  $js->decode('"\"\n\\\\\r\t\f\b"');
  $js->ascii->utf8->encode(chr 0x8000);

  sub Temp::TO_JSON { 7 }
  $js->encode ( bless { k => 1 }, Temp:: );

  sub Temp1::FREEZE { (3,1,2) }
  $js->encode ( bless { k => 1 }, Temp1:: );

} '<', 1;

# leak on allow_nonref croak, GH 206
leaks_cmp_ok{
    eval { decode_json('"asdf"') };
    #print $@;
}  '<', 1;

# illegal unicode croak
leaks_cmp_ok{
    eval { decode_json("{\"\x{c2}\x{c2}\"}") };
    #print $@;
}  '<', 1;

# wrong type croak
leaks_cmp_ok{
    use Cpanel::JSON::XS::Type;
    my $js = Cpanel::JSON::XS->new->canonical->require_types;
    eval { $js->encode([0], JSON_TYPE_FLOAT) };
    #print $@;
}  '<', 1;