Skip to content

realloc() kills source pointer when fails #3953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
d-a-v opened this issue Dec 12, 2017 · 3 comments
Closed

realloc() kills source pointer when fails #3953

d-a-v opened this issue Dec 12, 2017 · 3 comments

Comments

@d-a-v
Copy link
Collaborator

d-a-v commented Dec 12, 2017

On master, this sketch below would be correct if free() was not commented.
But the fact is that free() must be commented for it to work flawlessly endlessly looping at every ~34KB,
with otherwise a nice Fatal exception 3(LoadStoreErrorCause) crash in umm's check_poison().
This seems to be a bug in umm.
Discovered while trying to debug #3699 in with a too large file uploaded to ESP8266WebServer.

Can someone reproduce and confirm ?

void setup()
{
  Serial.begin(115200);
  Serial.setDebugOutput(true);
}

#define INC 100
size_t len = 0;
char* buf = NULL;

void loop()
{
  if (!buf)
  {
    os_printf(":1\n");
    buf = (char*)malloc(INC);
    if (buf)
      len = INC;
    else
      os_printf(":1null\n");
  }
  else
  {
    os_printf(":re %d -> %d\n", len, len + INC);
    char* newbuf = (char*)realloc(buf, len + INC);
    if (!newbuf)
    {
      os_printf(":re null\n");
      //free(buf);   <--- BUF IS NO MORE ALLOCATED WHERE IT SHOULD BE
      len = 0;
      buf = NULL;
    }
    else
    {
      len += INC;
      buf = newbuf;
    }
  }
}
@d-a-v
Copy link
Collaborator Author

d-a-v commented Dec 12, 2017

possibly related: bug in umm realloc()

@d-a-v
Copy link
Collaborator Author

d-a-v commented Dec 12, 2017

Sadly, same bug is triggered with upstream umm_malloc.
I'm afraid this may be the reason of at least lots of HTTP bugs here.
We can't really temporarily replace realloc with malloc/memcpy/free.
@igrr what was beeing used before umm_malloc ?
We could revert until umm_malloc is fixed.

@d-a-v
Copy link
Collaborator Author

d-a-v commented Dec 12, 2017

Then at least WString.cpp must be reviewed #3555 #3516

d-a-v added a commit to d-a-v/Arduino that referenced this issue Dec 13, 2017
@devyte devyte closed this as completed in cb723a5 Dec 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant