Ticket #12152: 0001-When-realloc-address-size-returns-NULL-address-must-.patch

File 0001-When-realloc-address-size-returns-NULL-address-must-.patch, 1.0 KB (added by philcostin, 9 years ago)
  • src/add-ons/kernel/network/stack/interfaces.cpp

    From 8a146226c82403cef454e33a156c1d929575c504 Mon Sep 17 00:00:00 2001
    From: Phil Costin <philcostin@hotmail.com>
    Date: Sat, 13 Jun 2015 23:28:06 +0100
    Subject: [PATCH] When realloc(address, size) returns NULL, address must be
     freed manually.
    
    ---
     src/add-ons/kernel/network/stack/interfaces.cpp | 9 +++++++--
     1 file changed, 7 insertions(+), 2 deletions(-)
    
    diff --git a/src/add-ons/kernel/network/stack/interfaces.cpp b/src/add-ons/kernel/network/stack/interfaces.cpp
    index 20b4110..b9de8a6 100644
    a b InterfaceAddress::Prepare(sockaddr** _address, size_t size)  
    410410    sockaddr* address = *_address;
    411411
    412412    if (address == NULL || size > address->sa_len) {
    413         address = (sockaddr*)realloc(address, size);
    414         if (address == NULL)
     413        sockaddr *resized = (sockaddr*)realloc(address, size);
     414
     415        if (resized == NULL) {
     416            free(address);
    415417            return NULL;
     418        } else {
     419            address = resized;
     420        }
    416421    }
    417422
    418423    address->sa_len = size;