Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] libcurl: Free up headers list to prevent memory leak #726

Merged
merged 3 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions codegens/libcurl/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ self = module.exports = {
if (body.mode === 'formdata' && options.useMimeType) {
snippet += indentString + 'curl_mime_free(mime);\n';
}
if (headersData) {
snippet += indentString + 'curl_slist_free_all(headers);\n';
}
snippet += '}\n';
snippet += 'curl_easy_cleanup(curl);\n';
(options.includeBoilerplate) &&
Expand Down
32 changes: 32 additions & 0 deletions codegens/libcurl/test/unit/convert.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,38 @@ describe('libcurl convert function', function () {
expect(snippet).to.include('curl_mime_name(part, "invalid src");');
});
});

it('should free up headers list after request is sent', function () {
var request = new sdk.Request({
'method': 'GET',
'header': [
{
'key': 'Accept',
'value': 'application/json'
},
{
'key': 'Content-Type',
'value': 'application/json'
}
],
'url': {
'raw': 'https://google.com',
'protocol': 'https',
'host': [
'google',
'com'
]
}
});
convert(request, {}, function (error, snippet) {
if (error) {
expect.fail(null, null, error);
}
expect(snippet).to.be.a('string');
expect(snippet).to.include('curl_slist_free_all(headers)');
});
});

});

describe('getOptions function', function () {
Expand Down
32 changes: 9 additions & 23 deletions test/codegen/newman/fixtures/basicCollection.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info": {
"_postman_id": "f52ee07d-6345-4220-89af-e6696b3c0122",
"_postman_id": "b303fb8b-9b21-4429-b00f-33b6a7efa186",
"name": "Basic Collection",
"description": "This collection contains requests that will be used to test validity of plugin created to convert postman request into code snippet of particular language.",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
Expand All @@ -12,7 +12,6 @@
{
"listen": "test",
"script": {
"id": "34edbfa7-7d32-42d6-8397-af2378c3aaa4",
"exec": [
""
],
Expand Down Expand Up @@ -53,7 +52,6 @@
},
{
"name": "Request Headers",
"event": [],
"request": {
"method": "GET",
"header": [
Expand Down Expand Up @@ -95,7 +93,6 @@
{
"listen": "test",
"script": {
"id": "e150d55b-0273-430a-9e1d-11969b433734",
"exec": [
""
],
Expand Down Expand Up @@ -141,7 +138,6 @@
{
"listen": "test",
"script": {
"id": "1bfe1fc3-c244-4a42-83c5-1a0d94d56ffd",
"exec": [
""
],
Expand Down Expand Up @@ -188,7 +184,6 @@
{
"listen": "test",
"script": {
"id": "a3ddecd1-e89d-426d-995c-0d6a678caa91",
"exec": [
"var responseJSON;",
"",
Expand Down Expand Up @@ -216,8 +211,7 @@
"header": [
{
"key": "Content-Type",
"value": "text/plain",
"disabled": false
"value": "text/plain"
}
],
"body": {
Expand Down Expand Up @@ -245,7 +239,6 @@
{
"listen": "test",
"script": {
"id": "e926912d-1c99-4c54-9b53-91c8f63acef0",
"exec": [
""
],
Expand Down Expand Up @@ -312,7 +305,6 @@
{
"listen": "test",
"script": {
"id": "d211bdad-60b3-4cd6-869f-853377bf03ef",
"exec": [
""
],
Expand Down Expand Up @@ -353,7 +345,6 @@
{
"listen": "test",
"script": {
"id": "532fef57-48fd-4ffe-ac7e-f5a7e32facc2",
"exec": [
""
],
Expand Down Expand Up @@ -394,7 +385,6 @@
{
"listen": "test",
"script": {
"id": "8bbbbc5b-2983-4979-8347-3ced95a69f7e",
"exec": [
""
],
Expand Down Expand Up @@ -435,7 +425,6 @@
{
"listen": "test",
"script": {
"id": "48da0505-470f-4cf3-bb77-30665415af60",
"exec": [
""
],
Expand Down Expand Up @@ -618,7 +607,6 @@
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"var responseJSON;",
"",
Expand All @@ -634,7 +622,8 @@
"",
"tests['response has PUT data'] = _.has(responseJSON, 'data');",
"tests['response matches the data sent in request'] = (responseJSON.data && responseJSON.data.length === 256);"
]
],
"type": "text/javascript"
}
}
],
Expand All @@ -646,16 +635,15 @@
"value": "text/plain"
}
],
"body": {},
"url": {
"raw": "https://mockbin.org/request",
"raw": "https://postman-echo.com/delete",
"protocol": "https",
"host": [
"mockbin",
"org"
"postman-echo",
"com"
],
"path": [
"request"
"delete"
]
},
"description": "The HTTP `DELETE` method is used to delete resources on a server. The exact\nuse of `DELETE` requests depends on the server implementation. In general, \n`DELETE` requests support both, Query String parameters as well as a Request \nBody.\n\nThis endpoint accepts an HTTP `DELETE` request and provides debug information\nsuch as the HTTP headers, Query String arguments, and the Request Body."
Expand All @@ -667,7 +655,6 @@
{
"listen": "prerequest",
"script": {
"id": "e80b6162-6c90-4150-bfa1-7f42f11c8f64",
"type": "text/javascript",
"exec": [
""
Expand All @@ -677,12 +664,11 @@
{
"listen": "test",
"script": {
"id": "538efa04-97ce-456c-a5a1-772c466591d5",
"type": "text/javascript",
"exec": [
""
]
}
}
]
}
}
16 changes: 4 additions & 12 deletions test/codegen/newman/fixtures/redirectCollection.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info": {
"_postman_id": "3ef1c00f-c58f-4604-8419-7a4931958235",
"_postman_id": "17d62db7-ca12-4298-8782-1d6f018c7be2",
"name": "Redirect test",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
Expand All @@ -11,23 +11,15 @@
"method": "GET",
"header": [],
"url": {
"raw": "https://mockbin.org/redirect/302/1/?to=https://postman-echo.com/get",
"raw": "https://httpbin.org/redirect/1",
"protocol": "https",
"host": [
"mockbin",
"httpbin",
"org"
],
"path": [
"redirect",
"302",
"1",
""
],
"query": [
{
"key": "to",
"value": "https://postman-echo.com/get"
}
"1"
]
}
},
Expand Down
Loading