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
This commit is contained in:
parent
af80820a57
commit
84f210952c
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=327898
@ -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
|
||||
|
@ -187,7 +187,7 @@ static MALLOC_DEFINE(M_SCTPNAT, "sctpnat", "sctp nat dbs");
|
||||
/* 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, struct ip *pip,
|
||||
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, struct ip *pip,
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user