Skip to content

Bug:An exception branch handling may cause a memory leak #25

Open
@coolc4

Description

@coolc4

edrav2/eprj/curl/lib/escape.c

char *curl_easy_escape(struct Curl_easy *data, const char *string,
int inlength)
{
....

alloc = (inlength?(size_t)inlength:strlen(string)) + 1;
newlen = alloc;

//malloc the ns memery
ns = malloc(alloc);
if(!ns)
return NULL;
//malloc ok

length = alloc-1;
while(length--) {
unsigned char in = string; / we need to treat the characters unsigned */

if(Curl_isunreserved(in))
  /* just copy this */
  ns[strindex++] = in;
else {
  /* encode it */
  newlen += 2; /* the size grows with two, since this'll become a %XX */
  if(newlen > alloc) {
    alloc *= 2;
    testing_ptr = Curl_saferealloc(ns, alloc);
    if(!testing_ptr)
      return NULL;
      // Here  will cause the memery leak.
    
.....

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions