Skip to content

Commit 6ee195a

Browse files
authored
prevent double free in WRITEFUNCTION_BUF (#111)
1 parent f4a28b9 commit 6ee195a

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

curl-helper.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -887,12 +887,15 @@ static size_t cb_WRITEFUNCTION_BUF(char *ptr, size_t size, size_t nmemb, void *d
887887
buf = Field(conn->ocamlValues, Ocaml_CALLBACKBUFFER);
888888
if (buf == Val_unit)
889889
{
890-
buf = caml_ba_alloc_dims(CAML_BA_UINT8 | CAML_BA_C_LAYOUT | CAML_BA_EXTERNAL, 1, NULL, 0);
890+
buf = caml_ba_alloc_dims(CAML_BA_UINT8 | CAML_BA_C_LAYOUT | CAML_BA_EXTERNAL, 1, ptr, size*nmemb);
891891
Store_field(conn->ocamlValues, Ocaml_CALLBACKBUFFER, buf);
892892
}
893-
struct caml_ba_array* ba = Caml_ba_array_val(buf);
894-
ba->dim[0]=size*nmemb;
895-
ba->data=ptr;
893+
else
894+
{
895+
struct caml_ba_array* ba = Caml_ba_array_val(buf);
896+
ba->dim[0]=size*nmemb;
897+
ba->data=ptr;
898+
}
896899
result = caml_callback_exn(Field(conn->ocamlValues, Ocaml_WRITEFUNCTION), buf);
897900

898901
size_t r = 0;

0 commit comments

Comments
 (0)