File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,7 @@ public function close()
133
133
if (is_resource ($ this ->curl )) {
134
134
curl_close ($ this ->curl );
135
135
}
136
+ $ this ->options = null ;
136
137
$ this ->json_decoder = null ;
137
138
}
138
139
Original file line number Diff line number Diff line change @@ -1282,4 +1282,38 @@ public function testRequestMethodSuccessiveOptionsRequests()
1282
1282
Helper \test ($ test , 'OPTIONS ' , 'DELETE ' );
1283
1283
Helper \test ($ test , 'OPTIONS ' , 'HEAD ' );
1284
1284
}
1285
+
1286
+ public function testMemoryLeak ()
1287
+ {
1288
+ ob_start ();
1289
+ echo '[ ' ;
1290
+ for ($ i = 0 ; $ i < 10 ; $ i ++) {
1291
+ if ($ i >= 1 ) {
1292
+ echo ', ' ;
1293
+ }
1294
+ echo '{"before": ' . memory_get_usage () . ', ' ;
1295
+ $ curl = new Curl ();
1296
+ $ curl ->close ();
1297
+ echo '"after": ' . memory_get_usage () . '} ' ;
1298
+ sleep (1 );
1299
+ }
1300
+ echo '] ' ;
1301
+ $ html = ob_get_contents ();
1302
+ ob_end_clean ();
1303
+ $ results = json_decode ($ html , true );
1304
+
1305
+ // Ensure memory does not leak excessively after instantiating a new
1306
+ // Curl instance and cleaning up. Memory diffs in the 2000-6000+ range
1307
+ // have indicated a memory leak.
1308
+ $ max_memory_diff = 1000 ;
1309
+ foreach ($ results as $ i => $ result ) {
1310
+ $ memory_diff = $ result ['after ' ] - $ result ['before ' ];;
1311
+ echo 'diff: ' . $ memory_diff . "\n" ;
1312
+
1313
+ // Skip the first test to allow memory usage to settle.
1314
+ if ($ i >= 1 ) {
1315
+ $ this ->assertLessThan ($ max_memory_diff , $ memory_diff );
1316
+ }
1317
+ }
1318
+ }
1285
1319
}
You can’t perform that action at this time.
0 commit comments