MCPcopy Index your code
hub / github.com/nodejs/node / demoBug

Function demoBug

test/parallel/test-http-parser-bad-ref.js:24–71  ·  view source on GitHub ↗
(part1, part2)

Source from the content-addressed store, hash-verified

22}
23
24function demoBug(part1, part2) {
25 flushPool();
26
27 const parser = new HTTPParser();
28 parser.initialize(HTTPParser.REQUEST, {});
29
30 parser.headers = [];
31 parser.url = '';
32
33 parser[kOnHeaders] = function(headers, url) {
34 parser.headers = parser.headers.concat(headers);
35 parser.url += url;
36 };
37
38 parser[kOnHeadersComplete] = function(info) {
39 headersComplete++;
40 console.log('url', info.url);
41 };
42
43 parser[kOnBody] = () => {};
44
45 parser[kOnMessageComplete] = function() {
46 messagesComplete++;
47 };
48
49
50 // We use a function to eliminate references to the Buffer b
51 // We want b to be GCed. The parser will hold a bad reference to it.
52 (function() {
53 const b = Buffer.from(part1);
54 flushPool();
55
56 console.log('parse the first part of the message');
57 parser.execute(b, 0, b.length);
58 })();
59
60 flushPool();
61
62 (function() {
63 const b = Buffer.from(part2);
64
65 console.log('parse the second part of the message');
66 parser.execute(b, 0, b.length);
67 parser.finish();
68 })();
69
70 flushPool();
71}
72
73
74demoBug('POST /1', '/22 HTTP/1.1\r\n' +

Callers 1

Calls 7

flushPoolFunction · 0.85
concatMethod · 0.80
initializeMethod · 0.45
logMethod · 0.45
fromMethod · 0.45
executeMethod · 0.45
finishMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…