URL:
  <http://savannah.nongnu.org/bugs/?40535>

                 Summary: realloc(xxx, 0) doesn't free
                 Project: AVR C Runtime Library
            Submitted by: glglgl
            Submitted on: So 10 Nov 2013 11:11:09 GMT
                Category: Library
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: libc code
                  Status: None
        Percent Complete: 0%
             Assigned to: None
        Originator Email: 
             Open/Closed: Open
         Discussion Lock: Any
                 Release: 1.8.0
           Fixed Release: None

    _______________________________________________________

Details:

realloc(xxx, 0) is supposed to free the given memory block if xxx is not NULL,
If xxx is NULL, realloc() is supposed to work like malloc().

So I suggest to modify

http://svn.sv.gnu.org/viewvc/trunk/avr-libc/libc/stdlib/realloc.c?revision=2127&root=avr-libc&view=markup

in that way to add after

        /* Trivial case, required by C standard. */
        if (ptr == 0)
                return malloc(len);

the lines

        /* Another trivial case, required by C standard. */
        if (len == 0) {
                free(ptr);
                return NULL;
        }

because in this case

* realloc(NULL, 0) returns the same as malloc(0)
* realloc(anythingelse, 0) does free(anythingelse).

This behaviour is required by the standard.




    _______________________________________________________

Reply to this item at:

  <http://savannah.nongnu.org/bugs/?40535>

_______________________________________________
  Nachricht gesendet von/durch Savannah
  http://savannah.nongnu.org/


_______________________________________________
AVR-libc-dev mailing list
AVR-libc-dev@nongnu.org
https://lists.nongnu.org/mailman/listinfo/avr-libc-dev

Reply via email to