Don't lose an allocated pointer if realloc() fails.
Free it instead. Pointed out by: Theo de Raadt
This commit is contained in:
parent
44ab8b53f2
commit
fc254be9bd
@ -17,7 +17,7 @@
|
|||||||
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
||||||
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*
|
*
|
||||||
* $Id: route.c,v 1.51 1998/06/27 23:48:53 brian Exp $
|
* $Id: route.c,v 1.52 1998/07/28 21:54:54 brian Exp $
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -236,17 +236,22 @@ Index2Nam(int idx)
|
|||||||
dl = (struct sockaddr_dl *)(ifm + 1);
|
dl = (struct sockaddr_dl *)(ifm + 1);
|
||||||
if (ifm->ifm_index > 0) {
|
if (ifm->ifm_index > 0) {
|
||||||
if (ifm->ifm_index > have) {
|
if (ifm->ifm_index > have) {
|
||||||
|
char **newifs;
|
||||||
|
|
||||||
had = have;
|
had = have;
|
||||||
have = ifm->ifm_index + 5;
|
have = ifm->ifm_index + 5;
|
||||||
if (had)
|
if (had)
|
||||||
ifs = (char **)realloc(ifs, sizeof(char *) * have);
|
newifs = (char **)realloc(ifs, sizeof(char *) * have);
|
||||||
else
|
else
|
||||||
ifs = (char **)malloc(sizeof(char *) * have);
|
newifs = (char **)malloc(sizeof(char *) * have);
|
||||||
if (!ifs) {
|
if (!newifs) {
|
||||||
log_Printf(LogDEBUG, "Index2Nam: %s\n", strerror(errno));
|
log_Printf(LogDEBUG, "Index2Nam: %s\n", strerror(errno));
|
||||||
nifs = 0;
|
nifs = 0;
|
||||||
|
if (ifs)
|
||||||
|
free(ifs);
|
||||||
return "???";
|
return "???";
|
||||||
}
|
}
|
||||||
|
ifs = newifs;
|
||||||
memset(ifs + had, '\0', sizeof(char *) * (have - had));
|
memset(ifs + had, '\0', sizeof(char *) * (have - had));
|
||||||
}
|
}
|
||||||
if (ifs[ifm->ifm_index-1] == NULL) {
|
if (ifs[ifm->ifm_index-1] == NULL) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user