Skip to content

Commit cb7a59c

Browse files
authored
Merge pull request #164 from moteus/reset_slist_option
Fix. Cleanup slists references in the reset function
2 parents 29d8667 + c8b5f86 commit cb7a59c

File tree

4 files changed

+44
-13
lines changed

4 files changed

+44
-13
lines changed

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ install:
3636
)
3737
- if not exist c:\hererocks (
3838
pip install hererocks &&
39-
hererocks c:\hererocks --%LUA% --target %HR_TARGET% -rlatest
39+
hererocks c:\hererocks --%LUA% --target %HR_TARGET% -r2.4.4
4040
)
4141
- call c:\hererocks\bin\activate
4242
- luarocks show luarocks-fetch-gitrec >nul 2>&1 || luarocks install luarocks-fetch-gitrec

src/lceasy.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,10 @@ static int lcurl_easy_reset(lua_State *L){
292292
lua_settop(L, 1);
293293

294294
if(p->storage != LUA_NOREF){
295+
int i;
296+
for (i = 0; i < LCURL_LIST_COUNT; ++i) {
297+
p->lists[i] = LUA_NOREF;
298+
}
295299
lcurl_storage_free(L, p->storage);
296300
p->storage = lcurl_storage_init(L);
297301
lua_settop(L, 1);

src/lcurl.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@
2525
# define LCURL_EXPORT_API LUALIB_API
2626
#endif
2727

28+
static const char* LCURL_REGISTRY = "LCURL Registry";
29+
static const char* LCURL_USERVAL = "LCURL Uservalues";
30+
#if LCURL_CURL_VER_GE(7,56,0)
31+
static const char* LCURL_MIME_EASY_MAP = "LCURL Mime easy";
32+
#endif
33+
34+
#if LCURL_CURL_VER_GE(7,56,0)
35+
#define NUP 3
36+
#else
37+
#define NUP 2
38+
#endif
39+
2840
static int lcurl_easy_new_safe(lua_State *L){
2941
return lcurl_easy_create(L, LCURL_ERROR_RETURN);
3042
}
@@ -78,6 +90,11 @@ static int lcurl_version(lua_State *L){
7890
return 1;
7991
}
8092

93+
static int lcurl_debug_getregistry(lua_State *L) {
94+
lua_rawgetp(L, LUA_REGISTRYINDEX, LCURL_REGISTRY);
95+
return 1;
96+
}
97+
8198
static int push_upper(lua_State *L, const char *str){
8299
char buffer[128];
83100
size_t i, n = strlen(str);
@@ -192,7 +209,9 @@ static const struct luaL_Reg lcurl_functions[] = {
192209
#endif
193210
{"version", lcurl_version },
194211
{"version_info", lcurl_version_info },
195-
212+
213+
{"__getregistry", lcurl_debug_getregistry},
214+
196215
{NULL,NULL}
197216
};
198217

@@ -208,6 +227,8 @@ static const struct luaL_Reg lcurl_functions_safe[] = {
208227
{"version", lcurl_version },
209228
{"version_info", lcurl_version_info },
210229

230+
{ "__getregistry", lcurl_debug_getregistry },
231+
211232
{NULL,NULL}
212233
};
213234

@@ -222,17 +243,6 @@ static const lcurl_const_t lcurl_flags[] = {
222243

223244
static volatile int LCURL_INIT = 0;
224245

225-
static const char* LCURL_REGISTRY = "LCURL Registry";
226-
static const char* LCURL_USERVAL = "LCURL Uservalues";
227-
#if LCURL_CURL_VER_GE(7,56,0)
228-
static const char* LCURL_MIME_EASY_MAP = "LCURL Mime easy";
229-
#endif
230-
231-
#if LCURL_CURL_VER_GE(7,56,0)
232-
#define NUP 3
233-
#else
234-
#define NUP 2
235-
#endif
236246

237247
#if LCURL_CURL_VER_GE(7,56,0)
238248
#define LCURL_PUSH_NUP(L) lua_pushvalue(L, -NUP-1);lua_pushvalue(L, -NUP-1);lua_pushvalue(L, -NUP-1);

test/test_easy.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,23 @@ function test_set_empty_array()
11031103
assert_not_match("X%-Custom:%s*value\r\n", headers)
11041104
end
11051105

1106+
function test_reset_slist()
1107+
c = curl.easy {
1108+
httpheader = {'X-Foo: 1'},
1109+
resolve = {'example.com:80:127.0.0.1'}
1110+
}
1111+
1112+
c:reset()
1113+
1114+
c:setopt{
1115+
httpheader = {'X-Foo: 2'},
1116+
resolve = {'example.com:80:127.0.0.1'}
1117+
}
1118+
1119+
local body, headers = assert_string(dump_request(c))
1120+
assert_match("X%-Foo:%s2\r\n", headers)
1121+
end
1122+
11061123
end
11071124

11081125
local _ENV = TEST_CASE'set_null' if ENABLE then

0 commit comments

Comments
 (0)