Skip to content

Commit e5f68e0

Browse files
committed
Fix. Validate allocated memory buffer.
1 parent 11d44d6 commit e5f68e0

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

src/lcmulti.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "lcerror.h"
2525
#include "lcutils.h"
2626
#include "lchttppost.h"
27-
#include <stdio.h>
2827

2928
#define LCURL_MULTI_NAME LCURL_PREFIX" Multi"
3029
static const char *LCURL_MULTI = LCURL_MULTI_NAME;
@@ -434,29 +433,24 @@ static int lcurl_opt_set_string_array_(lua_State *L, int opt){
434433
n = lua_rawlen(L, 2);
435434
}
436435

437-
fprintf(stderr, "\n>>> array size %d\n", n);
438-
439436
if(n == 0){
440437
code = curl_multi_setopt(p->curl, opt, 0);
441438
}
442439
else{
443440
int i;
444-
char const* *val = malloc(sizeof(char*) * (n + 1));
445-
fprintf(stderr, ">>> allocate size %d: %p\n", sizeof(char*) * (n + 1), val);
446-
if(!*val){
441+
char const**val = malloc(sizeof(char*) * (n + 1));
442+
if(!val){
447443
return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_MULTI, CURLM_OUT_OF_MEMORY);
448444
}
449445
for(i = 1; i <= n; ++i){
450446
lua_rawgeti(L, 2, i);
451-
fprintf(stderr, ">>> add string %s\n", lua_tostring(L, -1));
452447
val[i-1] = lua_tostring(L, -1);
453448
lua_pop(L, 1);
454449
}
455450
val[n] = NULL;
456451
code = curl_multi_setopt(p->curl, opt, val);
457452
free((void*)val);
458453
}
459-
fprintf(stderr, ">>> setopt result %d\n", code);
460454

461455
if(code != CURLM_OK){
462456
return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_MULTI, code);

0 commit comments

Comments
 (0)