From: Volker Lendecke Date: Fri, 4 Apr 2025 10:24:59 +0000 (+0200) Subject: lib: Save lines by avoiding explicit ZERO_STRUCTP calls X-Git-Tag: tevent-0.17.0~179 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0a0abbf2939bac2ffcf340aab35b9b1b98bcac96;p=thirdparty%2Fsamba.git lib: Save lines by avoiding explicit ZERO_STRUCTP calls SMB_CALLOC_ARRAY(..., 1) does this. Signed-off-by: Volker Lendecke Reviewed-by: Stefan Metzmacher --- diff --git a/source3/auth/pampass.c b/source3/auth/pampass.c index 0be7f9f9d1f..03d2fe69286 100644 --- a/source3/auth/pampass.c +++ b/source3/auth/pampass.c @@ -236,15 +236,13 @@ static struct chat_struct *make_pw_chat(const char *p) TALLOC_CTX *frame = talloc_stackframe(); while (1) { - t = SMB_MALLOC_P(struct chat_struct); + t = SMB_CALLOC_ARRAY(struct chat_struct, 1); if (!t) { DEBUG(0,("make_pw_chat: malloc failed!\n")); TALLOC_FREE(frame); return NULL; } - ZERO_STRUCTP(t); - DLIST_ADD_END(list, t); if (!next_token_talloc(frame, &p, &prompt, NULL)) { diff --git a/source3/lib/interface.c b/source3/lib/interface.c index 5f351999e41..4fbc17cccb7 100644 --- a/source3/lib/interface.c +++ b/source3/lib/interface.c @@ -319,13 +319,11 @@ static void add_interface(const struct iface_struct *ifs) return; } - iface = SMB_MALLOC_P(struct interface); + iface = SMB_CALLOC_ARRAY(struct interface, 1); if (!iface) { return; } - ZERO_STRUCTPN(iface); - iface->name = SMB_STRDUP(ifs->name); if (!iface->name) { SAFE_FREE(iface); diff --git a/source3/modules/vfs_readahead.c b/source3/modules/vfs_readahead.c index bb31b578b95..15f23e3f77d 100644 --- a/source3/modules/vfs_readahead.c +++ b/source3/modules/vfs_readahead.c @@ -139,13 +139,12 @@ static int readahead_connect(struct vfs_handle_struct *handle, if (ret < 0) { return ret; } - rhd = SMB_MALLOC_P(struct readahead_data); + rhd = SMB_CALLOC_ARRAY(struct readahead_data, 1); if (!rhd) { SMB_VFS_NEXT_DISCONNECT(handle); DEBUG(0,("readahead_connect: out of memory\n")); return -1; } - ZERO_STRUCTP(rhd); rhd->didmsg = False; rhd->off_bound = conv_str_size(lp_parm_const_string(SNUM(handle->conn), diff --git a/source3/modules/vfs_shadow_copy.c b/source3/modules/vfs_shadow_copy.c index 62b92918886..c99d933a5d3 100644 --- a/source3/modules/vfs_shadow_copy.c +++ b/source3/modules/vfs_shadow_copy.c @@ -85,7 +85,7 @@ static DIR *shadow_copy_fdopendir(vfs_handle_struct *handle, files_struct *fsp, return NULL; } - dirp = SMB_MALLOC_P(shadow_copy_Dir); + dirp = SMB_CALLOC_ARRAY(shadow_copy_Dir, 1); if (!dirp) { DEBUG(0,("shadow_copy_fdopendir: Out of memory\n")); SMB_VFS_NEXT_CLOSEDIR(handle,p); @@ -94,8 +94,6 @@ static DIR *shadow_copy_fdopendir(vfs_handle_struct *handle, files_struct *fsp, return NULL; } - ZERO_STRUCTP(dirp); - while (True) { struct dirent *d; diff --git a/source3/printing/printing_db.c b/source3/printing/printing_db.c index d54a39a9922..ee538e2999b 100644 --- a/source3/printing/printing_db.c +++ b/source3/printing/printing_db.c @@ -87,12 +87,11 @@ struct tdb_print_db *get_print_db_byname(const char *printername) if (!p) { /* Create one. */ - p = SMB_MALLOC_P(struct tdb_print_db); + p = SMB_CALLOC_ARRAY(struct tdb_print_db, 1); if (!p) { DEBUG(0,("get_print_db: malloc fail !\n")); return NULL; } - ZERO_STRUCTP(p); DLIST_ADD(print_db_head, p); } diff --git a/source3/registry/regfio.c b/source3/registry/regfio.c index 2ddac2179b2..a9b8ce8b7e4 100644 --- a/source3/registry/regfio.c +++ b/source3/registry/regfio.c @@ -1240,11 +1240,10 @@ out: { REGF_FILE *rb; - if ( !(rb = SMB_MALLOC_P(REGF_FILE)) ) { + if (!(rb = SMB_CALLOC_ARRAY(REGF_FILE, 1))) { DEBUG(0,("ERROR allocating memory\n")); return NULL; } - ZERO_STRUCTP( rb ); rb->fd = -1; rb->ignore_checksums = false; diff --git a/source3/winbindd/winbindd_cache.c b/source3/winbindd/winbindd_cache.c index 7a000c48259..96fee6c4218 100644 --- a/source3/winbindd/winbindd_cache.c +++ b/source3/winbindd/winbindd_cache.c @@ -3467,14 +3467,12 @@ static int traverse_fn_get_credlist(TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DAT if (strncmp((const char *)kbuf.dptr, "CRED/", 5) == 0) { - cred = SMB_MALLOC_P(struct cred_list); + cred = SMB_CALLOC_ARRAY(struct cred_list, 1); if (cred == NULL) { DBG_ERR("traverse_fn_remove_first_creds: failed to malloc new entry for list\n"); return -1; } - ZERO_STRUCTP(cred); - /* save a copy of the key */ fstrcpy(cred->name, (const char *)kbuf.dptr);