diff options
author | Pierre-Yves Ritschard <pyr@cvs.openbsd.org> | 2009-01-30 21:00:43 +0000 |
---|---|---|
committer | Pierre-Yves Ritschard <pyr@cvs.openbsd.org> | 2009-01-30 21:00:43 +0000 |
commit | 02bfd51be8dc8fa6a4b9f1fd9d040b5f937310b7 (patch) | |
tree | 668d7ebd42f99bdfa7e09f1979837469e190b87d | |
parent | 427bc222dda750a3074d9a85225832757ca3c392 (diff) |
avoid an alloc/free loop while looking for a bpf.
ok mbalmer@
-rw-r--r-- | usr.sbin/wake/wake.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/usr.sbin/wake/wake.c b/usr.sbin/wake/wake.c index 3feefc608b7..4e27bdf6040 100644 --- a/usr.sbin/wake/wake.c +++ b/usr.sbin/wake/wake.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wake.c,v 1.11 2009/01/29 15:50:03 mbalmer Exp $ */ +/* $OpenBSD: wake.c,v 1.12 2009/01/30 21:00:42 pyr Exp $ */ /* * Copyright (C) 2006,2007,2008,2009 Marc Balmer <mbalmer@openbsd.org> @@ -27,6 +27,7 @@ */ #include <sys/types.h> +#include <sys/param.h> #include <sys/queue.h> #include <sys/ioctl.h> #include <sys/socket.h> @@ -100,14 +101,13 @@ int get_bpf(void) { int i, fd; - char *path; + char path[MAXPATHLEN]; for (i = 0;; i++) { - if (asprintf(&path, BPF_PATH_FORMAT, i) == -1) + if (snprintf(path, sizeof(path), BPF_PATH_FORMAT, i) == -1) return -1; fd = open(path, O_RDWR); - free(path); if (fd != -1) return fd; if (errno == EBUSY) |