svn commit: r327898 - head/sys/netinet/libalias
Pedro F. Giffuni
pfg at FreeBSD.org
Fri Jan 12 23:12:32 UTC 2018
Author: pfg
Date: Fri Jan 12 23:12:30 2018
New Revision: 327898
URL: https://svnweb.freebsd.org/changeset/base/327898
Log:
libalias: small memory allocation cleanups.
Make the calloc wrappers behave as expected by using mallocarray.
It is rather weird that the malloc wrappers also zeroes the memory: update
a comment to reflect at least two cases where it is expected.
Reviewed by: tuexen
Modified:
head/sys/netinet/libalias/alias_mod.h
head/sys/netinet/libalias/alias_sctp.c
Modified: head/sys/netinet/libalias/alias_mod.h
==============================================================================
--- head/sys/netinet/libalias/alias_mod.h Fri Jan 12 23:06:35 2018 (r327897)
+++ head/sys/netinet/libalias/alias_mod.h Fri Jan 12 23:12:30 2018 (r327898)
@@ -42,7 +42,7 @@ MALLOC_DECLARE(M_ALIAS);
/* Use kernel allocator. */
#if defined(_SYS_MALLOC_H_)
#define malloc(x) malloc(x, M_ALIAS, M_NOWAIT|M_ZERO)
-#define calloc(x, n) malloc(x*n)
+#define calloc(n, x) mallocarray((n), (x), M_ALIAS, M_NOWAIT|M_ZERO)
#define free(x) free(x, M_ALIAS)
#endif
#endif
Modified: head/sys/netinet/libalias/alias_sctp.c
==============================================================================
--- head/sys/netinet/libalias/alias_sctp.c Fri Jan 12 23:06:35 2018 (r327897)
+++ head/sys/netinet/libalias/alias_sctp.c Fri Jan 12 23:12:30 2018 (r327898)
@@ -187,7 +187,7 @@ static MALLOC_DEFINE(M_SCTPNAT, "sctpnat", "sctp nat d
/* Use kernel allocator. */
#ifdef _SYS_MALLOC_H_
#define sn_malloc(x) malloc(x, M_SCTPNAT, M_NOWAIT|M_ZERO)
-#define sn_calloc(n,x) sn_malloc((x) * (n))
+#define sn_calloc(n,x) mallocarray((n), (x), M_SCTPNAT, M_NOWAIT|M_ZERO)
#define sn_free(x) free(x, M_SCTPNAT)
#endif// #ifdef _SYS_MALLOC_H_
@@ -1104,7 +1104,7 @@ sctp_PktParser(struct libalias *la, int direction, str
if (*passoc == NULL) {/* out of resources */
return (SN_PARSE_ERROR_AS_MALLOC);
}
- /* Initialise association - malloc initialises memory to zeros */
+ /* Initialize association - sn_malloc initializes memory to zeros */
(*passoc)->state = SN_ID;
LIST_INIT(&((*passoc)->Gaddr)); /* always initialise to avoid memory problems */
(*passoc)->TableRegister = SN_NULL_TBL;
@@ -1168,7 +1168,7 @@ sctp_PktParser(struct libalias *la, int direction, str
if (*passoc == NULL) {/* out of resources */
return (SN_PARSE_ERROR_AS_MALLOC);
}
- /* Initialise association - malloc initialises memory to zeros */
+ /* Initialize association - sn_malloc initializes memory to zeros */
(*passoc)->state = SN_ID;
LIST_INIT(&((*passoc)->Gaddr)); /* always initialise to avoid memory problems */
(*passoc)->TableRegister = SN_NULL_TBL;
More information about the svn-src-all
mailing list