VirtualBox

Changeset 86412 in vbox for trunk/src/VBox/Runtime/r3/posix


Ignore:
Timestamp:
Oct 2, 2020 11:39:26 AM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
140713
Message:

IPRT/pipe: Adding RTPipeCloseEx w/ a fLeaveOpen parameter so we can prevent leaks via RTHandleGetStandard. Adding RTPIPE_N_LEAVE_OPEN to RTPipeFromNative. bugref:9841

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/posix/pipe-posix.cpp

    r82968 r86412  
    7070    /** Set if this is the read end, clear if it's the write end. */
    7171    bool                fRead;
     72    /** RTPipeFromNative: Leave it open on RTPipeClose. */
     73    bool                fLeaveOpen;
    7274    /** Atomically operated state variable.
    7375     *
     
    181183            if (pThisW)
    182184            {
    183                 pThisR->u32Magic = RTPIPE_MAGIC;
    184                 pThisW->u32Magic = RTPIPE_MAGIC;
    185                 pThisR->fd       = aFds[0];
    186                 pThisW->fd       = aFds[1];
    187                 pThisR->fRead    = true;
    188                 pThisW->fRead    = false;
    189                 pThisR->u32State = RTPIPE_POSIX_BLOCKING;
    190                 pThisW->u32State = RTPIPE_POSIX_BLOCKING;
     185                pThisR->u32Magic    = RTPIPE_MAGIC;
     186                pThisW->u32Magic    = RTPIPE_MAGIC;
     187                pThisR->fd          = aFds[0];
     188                pThisW->fd          = aFds[1];
     189                pThisR->fRead       = true;
     190                pThisW->fRead       = false;
     191                pThisR->fLeaveOpen  = false;
     192                pThisW->fLeaveOpen  = false;
     193                pThisR->u32State    = RTPIPE_POSIX_BLOCKING;
     194                pThisW->u32State    = RTPIPE_POSIX_BLOCKING;
    191195
    192196                *phPipeRead  = pThisR;
     
    213217
    214218
    215 RTDECL(int)  RTPipeClose(RTPIPE hPipe)
     219RTDECL(int)  RTPipeCloseEx(RTPIPE hPipe, bool fLeaveOpen)
    216220{
    217221    RTPIPEINTERNAL *pThis = hPipe;
     
    228232    int fd = pThis->fd;
    229233    pThis->fd = -1;
    230     close(fd);
     234    if (!fLeaveOpen && !pThis->fLeaveOpen)
     235        close(fd);
    231236
    232237    if (ASMAtomicReadU32(&pThis->u32State) & RTPIPE_POSIX_USERS_MASK)
     
    241246}
    242247
     248
     249RTDECL(int)  RTPipeClose(RTPIPE hPipe)
     250{
     251    return RTPipeCloseEx(hPipe, false /*fLeaveOpen*/);
     252}
     253
     254
    243255RTDECL(int)  RTPipeFromNative(PRTPIPE phPipe, RTHCINTPTR hNativePipe, uint32_t fFlags)
    244256{
    245257    AssertPtrReturn(phPipe, VERR_INVALID_POINTER);
    246     AssertReturn(!(fFlags & ~RTPIPE_N_VALID_MASK), VERR_INVALID_PARAMETER);
     258    AssertReturn(!(fFlags & ~RTPIPE_N_VALID_MASK_FN), VERR_INVALID_PARAMETER);
    247259    AssertReturn(!!(fFlags & RTPIPE_N_READ) != !!(fFlags & RTPIPE_N_WRITE), VERR_INVALID_PARAMETER);
    248260
     
    268280        return VERR_NO_MEMORY;
    269281
    270     pThis->u32Magic = RTPIPE_MAGIC;
    271     pThis->fd       = hNative;
    272     pThis->fRead    = !!(fFlags & RTPIPE_N_READ);
    273     pThis->u32State = fFd & O_NONBLOCK ? 0 : RTPIPE_POSIX_BLOCKING;
     282    pThis->u32Magic   = RTPIPE_MAGIC;
     283    pThis->fd         = hNative;
     284    pThis->fRead      = RT_BOOL(fFlags & RTPIPE_N_READ);
     285    pThis->fLeaveOpen = RT_BOOL(fFlags & RTPIPE_N_LEAVE_OPEN);
     286    pThis->u32State   = fFd & O_NONBLOCK ? 0 : RTPIPE_POSIX_BLOCKING;
    274287
    275288    /*
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