The third nit in ypldap code, and the most questionable one.

IMHO, there is no reason to dynamically allocate relatively small
internal structures without buffers in it:

        struct userent {
                RB_ENTRY(userent)                ue_name_node;
                RB_ENTRY(userent)                ue_uid_node;
                uid_t                            ue_uid;
                char                            *ue_line;
                char                            *ue_netid_line;
                gid_t                            ue_gid;
        };

        struct groupent {
                RB_ENTRY(groupent)               ge_name_node;
                RB_ENTRY(groupent)               ge_gid_node;
                gid_t                            ge_gid;
                char                            *ge_line;
        };

Okay?

--
WBR,
  Vadim Zhukov


Index: ypldap.c
===================================================================
RCS file: /cvs/src/usr.sbin/ypldap/ypldap.c,v
retrieving revision 1.21
diff -u -p -r1.21 ypldap.c
--- ypldap.c    20 Jan 2017 12:39:36 -0000      1.21
+++ ypldap.c    5 Dec 2017 10:09:45 -0000
@@ -383,53 +383,49 @@ main_dispatch_client(int fd, short event
                        main_start_update(env);
                        break;
                case IMSG_PW_ENTRY: {
-                       struct userent  *ue;
+                       struct userent   ue;
                        size_t           len;
 
                        if (env->update_trashed)
                                break;
 
                        (void)memcpy(&ir, imsg.data, sizeof(ir));
-                       if ((ue = calloc(1, sizeof(*ue))) == NULL ||
-                           (ue->ue_line = strdup(ir.ir_line)) == NULL) {
+                       if ((ue.ue_line = strdup(ir.ir_line)) == NULL) {
                                /*
                                 * should cancel tree update instead.
                                 */
                                fatal("out of memory");
                        }
-                       ue->ue_uid = ir.ir_key.ik_uid;
-                       len = strlen(ue->ue_line) + 1;
-                       ue->ue_line[strcspn(ue->ue_line, ":")] = '\0';
+                       ue.ue_uid = ir.ir_key.ik_uid;
+                       len = strlen(ue.ue_line) + 1;
+                       ue.ue_line[strcspn(ue.ue_line, ":")] = '\0';
                        if (RB_INSERT(user_name_tree, env->sc_user_names_t,
-                           ue) != NULL) { /* dup */
-                               free(ue->ue_line);
-                               free(ue);
+                           &ue) != NULL) { /* dup */
+                               free(ue.ue_line);
                        } else
                                env->sc_user_line_len += len;
                        break;
                }
                case IMSG_GRP_ENTRY: {
-                       struct groupent *ge;
+                       struct groupent  ge;
                        size_t           len;
 
                        if (env->update_trashed)
                                break;
 
                        (void)memcpy(&ir, imsg.data, sizeof(ir));
-                       if ((ge = calloc(1, sizeof(*ge))) == NULL ||
-                           (ge->ge_line = strdup(ir.ir_line)) == NULL) {
+                       if ((ge.ge_line = strdup(ir.ir_line)) == NULL) {
                                /*
                                 * should cancel tree update instead.
                                 */
                                fatal("out of memory");
                        }
-                       ge->ge_gid = ir.ir_key.ik_gid;
-                       len = strlen(ge->ge_line) + 1;
-                       ge->ge_line[strcspn(ge->ge_line, ":")] = '\0';
+                       ge.ge_gid = ir.ir_key.ik_gid;
+                       len = strlen(ge.ge_line) + 1;
+                       ge.ge_line[strcspn(ge.ge_line, ":")] = '\0';
                        if (RB_INSERT(group_name_tree, env->sc_group_names_t,
-                           ge) != NULL) { /* dup */
-                               free(ge->ge_line);
-                               free(ge);
+                           &ge) != NULL) { /* dup */
+                               free(ge.ge_line);
                        } else
                                env->sc_group_line_len += len;
                        break;

Reply via email to