* Fixed a memory leak in if_nameindex() - it never freed the buffer that
stored the interfaces from SIOCGIFCONF. * Fixed iteration over the ifreq structures; the returned structure per interface may not be equal to the size of ifreq. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37802 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2006, Haiku, Inc. All Rights Reserved.
|
* Copyright 2006-2010, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -14,6 +14,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <AutoDeleter.h>
|
||||||
|
|
||||||
|
|
||||||
namespace BPrivate {
|
namespace BPrivate {
|
||||||
class Socket {
|
class Socket {
|
||||||
@@ -93,6 +95,8 @@ if_nameindex(void)
|
|||||||
if (interfaces == NULL)
|
if (interfaces == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
MemoryDeleter deleter(interfaces);
|
||||||
|
|
||||||
config.ifc_len = count * sizeof(struct ifreq);
|
config.ifc_len = count * sizeof(struct ifreq);
|
||||||
config.ifc_req = interfaces;
|
config.ifc_req = interfaces;
|
||||||
if (ioctl(socket.FD(), SIOCGIFCONF, &config, sizeof(struct ifconf)) < 0)
|
if (ioctl(socket.FD(), SIOCGIFCONF, &config, sizeof(struct ifconf)) < 0)
|
||||||
@@ -104,8 +108,11 @@ if_nameindex(void)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
interfaceArray[i].if_index = interfaces[i].ifr_index;
|
interfaceArray[i].if_index = interfaces->ifr_index;
|
||||||
interfaceArray[i].if_name = strdup(interfaces[i].ifr_name);
|
interfaceArray[i].if_name = strdup(interfaces->ifr_name);
|
||||||
|
|
||||||
|
interfaces
|
||||||
|
= (ifreq*)((char*)interfaces + _SIZEOF_ADDR_IFREQ(interfaces[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
interfaceArray[count].if_index = 0;
|
interfaceArray[count].if_index = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user