Skip to content

Commit d43d634

Browse files
committed
[FIX] libcurl: Free up headers list to prevent memory leak
1 parent 2411e41 commit d43d634

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

codegens/libcurl/lib/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ self = module.exports = {
214214
if (body.mode === 'formdata' && options.useMimeType) {
215215
snippet += indentString + 'curl_mime_free(mime);\n';
216216
}
217+
if (headersData) {
218+
snippet += indentString + 'curl_slist_free_all(headers);\n';
219+
}
217220
snippet += '}\n';
218221
snippet += 'curl_easy_cleanup(curl);\n';
219222
(options.includeBoilerplate) &&

codegens/libcurl/test/unit/convert.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,38 @@ describe('libcurl convert function', function () {
145145
expect(snippet).to.include('curl_mime_name(part, "invalid src");');
146146
});
147147
});
148+
149+
it('should free up headers list after request is sent', function () {
150+
var request = new sdk.Request({
151+
'method': 'GET',
152+
'header': [
153+
{
154+
'key': 'Accept',
155+
'value': 'application/json'
156+
},
157+
{
158+
'key': 'Content-Type',
159+
'value': 'application/json'
160+
}
161+
],
162+
'url': {
163+
'raw': 'https://google.com',
164+
'protocol': 'https',
165+
'host': [
166+
'google',
167+
'com'
168+
]
169+
}
170+
});
171+
convert(request, {}, function (error, snippet) {
172+
if (error) {
173+
expect.fail(null, null, error);
174+
}
175+
expect(snippet).to.be.a('string');
176+
expect(snippet).to.include('curl_slist_free_all(headers)');
177+
});
178+
});
179+
148180
});
149181

150182
describe('getOptions function', function () {

0 commit comments

Comments
 (0)