Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

gzip.deflate memory leak #14

Open
dmich opened this Issue · 2 comments

1 participant

@dmich

we see a memory leaks in gzip.deflate. Are there any known issues?
Also question (why you never delete the temporary buffer allocated at line 154?)
154 char* buf = new char[len];
155 ssize_t written = DecodeWrite(buf, len, args[0], enc);
156 assert(written == len);
157

158 char* out;
159 int out_size;
160 int r = gzip->GzipDeflate(buf, len, &out, &out_size);
161

162 if (out_size==0) {
163 return scope.Close(String::New(""));
164 }
165

166 Local outString = Encode(out, out_size, BINARY);
167 free(out);
168 return scope.Close(outString);

@dmich

fix:

char* buf = new char[len];

if(buf == NULL){
  Local<Value> exception = Exception::TypeError(String::New("Out of memory"));
  return ThrowException(exception);
}

ssize_t written = DecodeWrite(buf, len, args[0], enc);
assert(written == len);

char* out;
int out_size;
int r = gzip->GzipDeflate(buf, len, &out, &out_size);

if (out_size==0) {
    if(out != NULL)
      free(out);
    if(buf != NULL)
      delete buf;
  return scope.Close(String::New(""));
}

Local<Value> outString = Encode(out, out_size, BINARY);

if(out != NULL)
  free(out);
if(buf != NULL)
  delete buf;

return scope.Close(outString);

}

@dmich

same for GunzipInflate(const Arguments& args)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.