Print this page
2831 svc.startd and svc.configd waste memory.

@@ -371,13 +371,15 @@
         if (snap != NULL)
                 scf_snapshot_destroy(snap);
         if (inst->ri_logstem != NULL)
                 startd_free(inst->ri_logstem, PATH_MAX);
         if (inst->ri_common_name != NULL)
-                startd_free(inst->ri_common_name, max_scf_value_size);
+                startd_free(inst->ri_common_name,
+                    strlen(inst->ri_common_name) + 1);
         if (inst->ri_C_common_name != NULL)
-                startd_free(inst->ri_C_common_name, max_scf_value_size);
+                startd_free(inst->ri_C_common_name,
+                    strlen(inst->ri_C_common_name) + 1);
         snap = NULL;
         inst->ri_logstem = NULL;
         inst->ri_common_name = NULL;
         inst->ri_C_common_name = NULL;
 

@@ -527,12 +529,29 @@
         default:
                 assert(0);
                 abort();
         }
 
-        switch (libscf_get_template_values(scf_inst, snap,
-            &inst->ri_common_name, &inst->ri_C_common_name)) {
+        r = libscf_get_template_values(scf_inst, snap,
+            &inst->ri_common_name, &inst->ri_C_common_name);
+
+        /*
+         * Copy our names to smaller buffers to reduce our memory footprint.
+         */
+        if (inst->ri_common_name != NULL) {
+                char *tmp = safe_strdup(inst->ri_common_name);
+                startd_free(inst->ri_common_name, max_scf_value_size);
+                inst->ri_common_name = tmp;
+        }
+
+        if (inst->ri_C_common_name != NULL) {
+                char *tmp = safe_strdup(inst->ri_C_common_name);
+                startd_free(inst->ri_C_common_name, max_scf_value_size);
+                inst->ri_C_common_name = tmp;
+        }
+
+        switch (r) {
         case 0:
                 break;
 
         case ECONNABORTED:
                 libscf_handle_rebind(h);

@@ -676,13 +695,15 @@
         startd_free((void *)inst->ri_i.i_fmri, strlen(inst->ri_i.i_fmri) + 1);
         uu_list_destroy(inst->ri_queue);
         if (inst->ri_logstem != NULL)
                 startd_free(inst->ri_logstem, PATH_MAX);
         if (inst->ri_common_name != NULL)
-                startd_free(inst->ri_common_name, max_scf_value_size);
+                startd_free(inst->ri_common_name,
+                    strlen(inst->ri_common_name) + 1);
         if (inst->ri_C_common_name != NULL)
-                startd_free(inst->ri_C_common_name, max_scf_value_size);
+                startd_free(inst->ri_C_common_name,
+                    strlen(inst->ri_C_common_name) + 1);
         startd_free(inst->ri_utmpx_prefix, max_scf_value_size);
         startd_free(inst, sizeof (restarter_inst_t));
         return (ENOENT);
 }
 

@@ -738,13 +759,15 @@
         uu_list_destroy(ri->ri_queue);
 
         startd_free((void *)ri->ri_i.i_fmri, strlen(ri->ri_i.i_fmri) + 1);
         startd_free(ri->ri_logstem, PATH_MAX);
         if (ri->ri_common_name != NULL)
-                startd_free(ri->ri_common_name, max_scf_value_size);
+                startd_free(ri->ri_common_name,
+                    strlen(ri->ri_common_name) + 1);
         if (ri->ri_C_common_name != NULL)
-                startd_free(ri->ri_C_common_name, max_scf_value_size);
+                startd_free(ri->ri_C_common_name,
+                    strlen(ri->ri_C_common_name) + 1);
         startd_free(ri->ri_utmpx_prefix, max_scf_value_size);
         (void) pthread_mutex_destroy(&ri->ri_lock);
         (void) pthread_mutex_destroy(&ri->ri_queue_lock);
         startd_free(ri, sizeof (restarter_inst_t));
 }

@@ -1839,10 +1862,11 @@
         if (uu_list_first(rip->ri_queue) != NULL)
                 goto again;
 
         rip->ri_queue_thread = 0;
         MUTEX_UNLOCK(&rip->ri_queue_lock);
+
 out:
         (void) scf_handle_unbind(h);
         scf_handle_destroy(h);
         free(fmri);
         return (NULL);