Print this page
9637 Memleak in pcibus.so`pci_slot_label_lookup.

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/fm/topo/modules/common/pcibus/pcibus_labels.c
          +++ new/usr/src/lib/fm/topo/modules/common/pcibus/pcibus_labels.c
↓ open down ↓ 213 lines elided ↑ open up ↑
 214  214  }
 215  215  
 216  216  /*
 217  217   * Do an overall slot label lookup for the device node.
 218  218   */
 219  219  char *
 220  220  pci_slot_label_lookup(topo_mod_t *mod, tnode_t *node, did_t *dp, did_t *pdp)
 221  221  {
 222  222          tnode_t *anode, *apnode;
 223  223          did_t *adp, *apdp;
 224      -        char *plat, *pp, *l, *ancestor_l = NULL, *new_l = NULL;
      224 +        char *plat, *pp, *l = NULL, *ancestor_l = NULL, *new_l = NULL;
 225  225          int err, b, d, f, done = 0;
 226  226          size_t len;
 227  227  
 228  228          did_BDF(dp, &b, &d, &f);
 229  229  
 230  230          topo_mod_dprintf(mod, "%s: entry: node=%p, node_name=%s, "
 231  231              "node_inst=%d, dp=%p, dp_bdf=%d/%d/%d, pdp=%p\n",
 232  232              __func__, node, topo_node_name(node), topo_node_instance(node),
 233  233              dp, b, d, f, pdp);
 234  234  
↓ open down ↓ 110 lines elided ↑ open up ↑
 345  345           * this node's label. Otherwise, do a full slot label lookup.
 346  346           */
 347  347          if (ancestor_l && l) {
 348  348                  topo_mod_dprintf(mod, "%s: node=%p: concatenating "
 349  349                      "ancestor_l=%s and l=%s\n",
 350  350                      __func__, node, ancestor_l, l);
 351  351                  len = strlen(ancestor_l) + strlen(l) + 2;
 352  352                  new_l = alloca(len);
 353  353                  (void) snprintf(new_l, len, "%s/%s", ancestor_l, l);
 354  354                  l = new_l;
 355      -        } else {
      355 +        } else if (topo_prop_get_string(node, FM_FMRI_AUTHORITY,
      356 +            FM_FMRI_AUTH_PRODUCT, &plat, &err) == 0) {
 356  357                  /*
 357      -                 * Get platform name used for lookups.
 358      -                 */
 359      -                if (topo_prop_get_string(node, FM_FMRI_AUTHORITY,
 360      -                    FM_FMRI_AUTH_PRODUCT, &plat, &err) < 0) {
 361      -                        (void) topo_mod_seterrno(mod, err);
 362      -                        return (NULL);
 363      -                }
 364      -                /*
 365  358                   * Trim SUNW, from the platform name
 366  359                   */
 367  360                  pp = strchr(plat, ',');
 368  361                  if (pp == NULL)
 369  362                          pp = plat;
 370  363                  else
 371  364                          ++pp;
 372  365                  /*
 373  366                   * Get device number used for lookup.
 374  367                   */
↓ open down ↓ 14 lines elided ↑ open up ↑
 389  382                          if ((l = (char *)did_physlot_name(pdp, d)) != NULL) {
 390  383                                  l = (char *)
 391  384                                      pci_label_slotname_lookup(mod, pp, l, dp);
 392  385                          }
 393  386                          if (l == NULL) {
 394  387                                  l = (char *)
 395  388                                      pci_label_missing_lookup(mod, pp, dp);
 396  389                          }
 397  390                  }
 398  391                  topo_mod_strfree(mod, plat);
      392 +        } else {
      393 +                (void) topo_mod_seterrno(mod, err);
      394 +                l = NULL;
 399  395          }
 400  396  
      397 +        topo_mod_strfree(mod, ancestor_l);
      398 +
 401  399          /*
 402  400           * If we calculated a slot label,  then save it in the
 403  401           * node's data structure so we can free it later.
 404  402           */
 405  403          if (l) {
 406  404                  if (did_slot_label_get(dp) != NULL)
 407  405                          topo_mod_strfree(mod, did_slot_label_get(dp));
 408  406                  l = topo_mod_strdup(mod, l);
 409  407                  did_slot_label_set(dp, l);
 410  408          }
↓ open down ↓ 99 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX