VirtualBox

Changeset 69593 in vbox


Ignore:
Timestamp:
Nov 6, 2017 12:44:18 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
118943
Message:

RTCat: Fixed handle leak.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/tools/RTCat.cpp

    r69434 r69593  
    195195    rc = RTGetOptInit(&GetState, cArgs, papszArgs, s_aOptions, RT_ELEMENTS(s_aOptions), 1,
    196196                      RTGETOPTINIT_FLAGS_OPTS_FIRST);
    197     if (RT_FAILURE(rc))
    198         return RTMsgErrorExit(RTEXITCODE_SYNTAX, "RTGetOptInit: %Rrc", rc);
    199 
    200     for (;;)
     197    if (RT_SUCCESS(rc))
    201198    {
    202         RTGETOPTUNION ValueUnion;
    203         int chOpt = RTGetOpt(&GetState, &ValueUnion);
    204         switch (chOpt)
     199        bool fContinue = true;
     200        do
    205201        {
    206             case 0:
    207                 /*
    208                  * If we've processed any files we're done.  Otherwise take
    209                  * input from stdin and write the output to stdout.
    210                  */
    211                 if (cProcessed > 0)
    212                     return rcExit;
    213                 ValueUnion.psz = "-";
    214                 RT_FALL_THRU();
    215             case VINF_GETOPT_NOT_OPTION:
     202            RTGETOPTUNION ValueUnion;
     203            int chOpt = RTGetOpt(&GetState, &ValueUnion);
     204            switch (chOpt)
    216205            {
    217                 RTVFSIOSTREAM hVfsSrc;
    218                 RTEXITCODE rcExit2 = rtCmdCatOpenInput(ValueUnion.psz, &hVfsSrc);
    219                 if (rcExit2 == RTEXITCODE_SUCCESS)
     206                case 0:
     207                    /*
     208                     * If we've processed any files we're done.  Otherwise take
     209                     * input from stdin and write the output to stdout.
     210                     */
     211                    if (cProcessed > 0)
     212                    {
     213                        fContinue = false;
     214                        break;
     215                    }
     216                    ValueUnion.psz = "-";
     217                    RT_FALL_THRU();
     218                case VINF_GETOPT_NOT_OPTION:
    220219                {
    221                     if (   Opts.fShowEnds
    222                         || Opts.fShowTabs
    223                         || Opts.fShowNonPrinting
    224                         || Opts.fSqueezeBlankLines
    225                         || Opts.fNumberLines
    226                         || Opts.fNumberNonBlankLines)
    227                         rcExit2 = rtCmdCatShowComplicated(hVfsOutput, hVfsSrc, ValueUnion.psz, &Opts);
    228                     else
    229                         rcExit2 = rtCmdCatShowRaw(hVfsOutput, hVfsSrc, ValueUnion.psz);
    230                     RTVfsIoStrmRelease(hVfsSrc);
     220                    RTVFSIOSTREAM hVfsSrc;
     221                    RTEXITCODE rcExit2 = rtCmdCatOpenInput(ValueUnion.psz, &hVfsSrc);
     222                    if (rcExit2 == RTEXITCODE_SUCCESS)
     223                    {
     224                        if (   Opts.fShowEnds
     225                            || Opts.fShowTabs
     226                            || Opts.fShowNonPrinting
     227                            || Opts.fSqueezeBlankLines
     228                            || Opts.fNumberLines
     229                            || Opts.fNumberNonBlankLines)
     230                            rcExit2 = rtCmdCatShowComplicated(hVfsOutput, hVfsSrc, ValueUnion.psz, &Opts);
     231                        else
     232                            rcExit2 = rtCmdCatShowRaw(hVfsOutput, hVfsSrc, ValueUnion.psz);
     233                        RTVfsIoStrmRelease(hVfsSrc);
     234                    }
     235                    if (rcExit2 != RTEXITCODE_SUCCESS)
     236                        rcExit = rcExit2;
     237                    cProcessed++;
     238                    break;
    231239                }
    232                 if (rcExit2 != RTEXITCODE_SUCCESS)
    233                     rcExit = rcExit2;
    234                 cProcessed++;
    235                 break;
     240
     241                case 'A':
     242                    Opts.fShowNonPrinting       = true;
     243                    Opts.fShowEnds              = true;
     244                    Opts.fShowTabs              = true;
     245                    break;
     246
     247                case 'b':
     248                    Opts.fNumberNonBlankLines   = true;
     249                    break;
     250
     251                case 'e':
     252                    Opts.fShowNonPrinting       = true;
     253                    RT_FALL_THRU();
     254                case 'E':
     255                    Opts.fShowEnds              = true;
     256                    break;
     257
     258                case 'l':
     259                    Opts.fAdvisoryOutputLock    = true;
     260                    break;
     261
     262                case 'n':
     263                    Opts.fNumberLines           = true;
     264                    Opts.fNumberNonBlankLines   = false;
     265                    break;
     266
     267                case 's':
     268                    Opts.fSqueezeBlankLines     = true;
     269                    break;
     270
     271                case 't':
     272                    Opts.fShowNonPrinting       = true;
     273                    RT_FALL_THRU();
     274                case 'T':
     275                    Opts.fShowTabs              = true;
     276                    break;
     277
     278                case 'u': /* currently ignored */
     279                    Opts.fUnbufferedOutput      = true;
     280                    break;
     281
     282                case 'v':
     283                    Opts.fShowNonPrinting       = true;
     284                    break;
     285
     286                case 'h':
     287                    RTPrintf("Usage: to be written\nOption dump:\n");
     288                    for (unsigned i = 0; i < RT_ELEMENTS(s_aOptions); i++)
     289                        RTPrintf(" -%c,%s\n", s_aOptions[i].iShort, s_aOptions[i].pszLong);
     290                    fContinue = false;
     291                    break;
     292
     293                case 'V':
     294                    RTPrintf("%sr%d\n", RTBldCfgVersion(), RTBldCfgRevision());
     295                    fContinue = false;
     296                    break;
     297
     298                default:
     299                    rcExit = RTGetOptPrintError(chOpt, &ValueUnion);
     300                    fContinue = false;
     301                    break;
    236302            }
    237 
    238             case 'A':
    239                 Opts.fShowNonPrinting       = true;
    240                 Opts.fShowEnds              = true;
    241                 Opts.fShowTabs              = true;
    242                 break;
    243 
    244             case 'b':
    245                 Opts.fNumberNonBlankLines   = true;
    246                 break;
    247 
    248             case 'e':
    249                 Opts.fShowNonPrinting       = true;
    250                 RT_FALL_THRU();
    251             case 'E':
    252                 Opts.fShowEnds              = true;
    253                 break;
    254 
    255             case 'l':
    256                 Opts.fAdvisoryOutputLock    = true;
    257                 break;
    258 
    259             case 'n':
    260                 Opts.fNumberLines           = true;
    261                 Opts.fNumberNonBlankLines   = false;
    262                 break;
    263 
    264             case 's':
    265                 Opts.fSqueezeBlankLines     = true;
    266                 break;
    267 
    268             case 't':
    269                 Opts.fShowNonPrinting       = true;
    270                 RT_FALL_THRU();
    271             case 'T':
    272                 Opts.fShowTabs              = true;
    273                 break;
    274 
    275             case 'u': /* currently ignored */
    276                 Opts.fUnbufferedOutput      = true;
    277                 break;
    278 
    279             case 'v':
    280                 Opts.fShowNonPrinting       = true;
    281                 break;
    282 
    283             case 'h':
    284                 RTPrintf("Usage: to be written\nOption dump:\n");
    285                 for (unsigned i = 0; i < RT_ELEMENTS(s_aOptions); i++)
    286                     RTPrintf(" -%c,%s\n", s_aOptions[i].iShort, s_aOptions[i].pszLong);
    287                 return RTEXITCODE_SUCCESS;
    288 
    289             case 'V':
    290                 RTPrintf("%sr%d\n", RTBldCfgVersion(), RTBldCfgRevision());
    291                 return RTEXITCODE_SUCCESS;
    292 
    293             default:
    294                 return RTGetOptPrintError(chOpt, &ValueUnion);
    295         }
     303        } while (fContinue);
    296304    }
     305    else
     306        rcExit = RTMsgErrorExit(RTEXITCODE_SYNTAX, "RTGetOptInit: %Rrc", rc);
     307    RTVfsIoStrmRelease(hVfsOutput);
     308    return rcExit;
    297309}
    298310
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette