libnv: add a wrapper around free(9) since in FreeBSD it can take NULL.

This commit is contained in:
rmind 2018-09-23 19:07:10 +00:00
parent 00cd7c0d25
commit 6bb96d27de
2 changed files with 14 additions and 4 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: nv_impl.h,v 1.4 2018/09/22 17:13:30 rmind Exp $ */
/* $NetBSD: nv_impl.h,v 1.5 2018/09/23 19:07:10 rmind Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@ -65,10 +65,11 @@ extern void *nv_calloc(size_t, size_t);
# endif
# define nv_realloc(buf, size) realloc((buf), (size), M_NVLIST, \
M_WAITOK)
# define nv_free(buf) free((buf), M_NVLIST)
# ifdef __FreeBSD__
# define nv_free(buf) free((buf), M_NVLIST)
# define nv_strdup(buf) strdup((buf), M_NVLIST)
# else
extern void nv_free(void *);
extern char *nv_strdup(const char *);
# endif
# define nv_vasprintf(ptr, ...) vasprintf(ptr, M_NVLIST, __VA_ARGS__)

View File

@ -1,4 +1,4 @@
/* $NetBSD: nv_kern_netbsd.c,v 1.3 2018/09/22 17:13:30 rmind Exp $ */
/* $NetBSD: nv_kern_netbsd.c,v 1.4 2018/09/23 19:07:10 rmind Exp $ */
/*-
* Copyright (c) 2018 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: nv_kern_netbsd.c,v 1.3 2018/09/22 17:13:30 rmind Exp $");
__RCSID("$NetBSD: nv_kern_netbsd.c,v 1.4 2018/09/23 19:07:10 rmind Exp $");
#if !defined(_KERNEL) && !defined(_STANDALONE)
#include <sys/mman.h>
@ -61,6 +61,15 @@ extern void dealloc(void *, unsigned int);
#ifndef _STANDALONE
#ifdef _KERNEL
void
nv_free(void *buf)
{
if (!buf) {
return;
}
free(buf, M_NVLIST);
}
int
nvlist_copyin(const nvlist_ref_t *nref, nvlist_t **nvlp, size_t lim)
{