Print this page
4229 mdb hangs on exit when long umem cache names exist
Reviewed by: Robert Mustacchi <rm@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/mdb/common/mdb/mdb_tab.c
          +++ new/usr/src/cmd/mdb/common/mdb/mdb_tab.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright (c) 2013 by Delphix. All rights reserved.
  23   23   * Copyright (c) 2012 Joyent, Inc. All rights reserved.
       24 + * Copyright (c) 2013 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  24   25   */
  25   26  /*
  26   27   * This file contains all of the interfaces for mdb's tab completion engine.
  27   28   * Currently some interfaces are private to mdb and its internal implementation,
  28   29   * those are in mdb_tab.h. Other pieces are public interfaces. Those are in
  29   30   * mdb_modapi.h.
  30   31   *
  31   32   * Memory allocations in tab completion context have to be done very carefully.
  32   33   * We need to think of ourselves as the same as any other command that is being
  33   34   * executed by the user, which means we must use UM_GC to handle being
↓ open down ↓ 353 lines elided ↑ open up ↑
 387  388  }
 388  389  
 389  390  /*
 390  391   * Determine whether the specified name is a valid tab completion for
 391  392   * the given command. If the name is a valid tab completion then
 392  393   * it will be saved in the mdb_tab_cookie_t.
 393  394   */
 394  395  void
 395  396  mdb_tab_insert(mdb_tab_cookie_t *mcp, const char *name)
 396  397  {
 397      -        size_t len, matches, index;
 398      -        uint_t flags;
      398 +        size_t matches, index;
 399  399          mdb_var_t *v;
 400      -        char *n;
 401      -        const char *nvn;
 402  400  
 403  401          /*
 404  402           * If we have a match set, then we want to verify that we actually match
 405  403           * it.
 406  404           */
 407  405          if (mcp->mtc_base != NULL &&
 408  406              strncmp(name, mcp->mtc_base, strlen(mcp->mtc_base)) != 0)
 409  407                  return;
 410  408  
 411  409          v = mdb_nv_lookup(&mcp->mtc_nv, name);
 412  410          if (v != NULL)
 413  411                  return;
 414  412  
 415      -        /*
 416      -         * Names that we get passed in may be longer than MDB_NV_NAMELEN which
 417      -         * is currently 31 including the null terminator. If that is the case,
 418      -         * then we're going to take care of allocating a string and holding it
 419      -         * for our caller. Note that we don't need to free it, because we're
 420      -         * allocating this with UM_GC.
 421      -         */
 422      -        flags = 0;
 423      -        len = strlen(name);
 424      -        if (len > MDB_NV_NAMELEN - 1) {
 425      -                n = mdb_alloc(len + 1, UM_SLEEP | UM_GC);
 426      -                (void) strcpy(n, name);
 427      -                nvn = n;
 428      -                flags |= MDB_NV_EXTNAME;
 429      -        } else {
 430      -                nvn = name;
 431      -        }
 432      -        flags |= MDB_NV_RDONLY;
 433      -
 434      -        (void) mdb_nv_insert(&mcp->mtc_nv, nvn, NULL, 0, flags);
      413 +        (void) mdb_nv_insert(&mcp->mtc_nv, name, NULL, 0, MDB_NV_RDONLY);
 435  414  
 436  415          matches = mdb_tab_size(mcp);
 437  416          if (matches == 1) {
 438      -                (void) strlcpy(mcp->mtc_match, nvn, MDB_SYM_NAMLEN);
      417 +                (void) strlcpy(mcp->mtc_match, name, MDB_SYM_NAMLEN);
 439  418          } else {
 440  419                  index = 0;
 441  420                  while (mcp->mtc_match[index] &&
 442      -                    mcp->mtc_match[index] == nvn[index])
      421 +                    mcp->mtc_match[index] == name[index])
 443  422                          index++;
 444  423  
 445  424                  mcp->mtc_match[index] = '\0';
 446  425          }
 447  426  }
 448  427  
 449  428  /*ARGSUSED*/
 450  429  static int
 451  430  tab_print_cb(mdb_var_t *v, void *ignored)
 452  431  {
↓ open down ↓ 231 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX