Shopify / mruby-engine

MRuby engine is a sandboxed scripting engine.
MIT License
80 stars 18 forks source link

Do not malloc when we meant to free #12

Closed singpolyma-shopify closed 8 years ago

singpolyma-shopify commented 8 years ago

Previously, if we were asked to free (size == 0) a NULL pointer (we observe mruby trying to do this in our tests) we would try to allocate with size of 0.

Instead we should simply report free success to the caller and do nothing.

alexsnaps commented 8 years ago

dlmalloc will actually do a tiny chunk allocation in that case... i.e. 0 doesn't mean no op

in-the-mood-for-mov commented 8 years ago

dlmalloc will actually do a tiny chunk allocation in that case... i.e. 0 doesn't mean no op

I that case should we return sizeof(void *) bytes?

alexsnaps commented 8 years ago
      nb = (bytes < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(bytes);

Where MIN_CHUNK_SIZE == ((MCHUNK_SIZE + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK) ... and there I stopped resolving macros... but did I read this wrong?

in-the-mood-for-mov commented 8 years ago

Ah yeah that makes sense.