VirtualBox

Changeset 108816 in vbox for trunk/src


Ignore:
Timestamp:
Apr 1, 2025 8:30:27 PM (2 weeks ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
168262
Message:

NAT/libslirp: fixed handle table leak which was causing disconnects on windows during high or sustained network traffic. bugref:10268

Location:
trunk/src/libs/libslirp-4.8.0/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/libslirp-4.8.0/src/nathandletable.c

    r105667 r108816  
    4949    }
    5050
    51     Log6Func(("Looking up %d on %p\n", fd, (void *)pNATHandleTable));
    5251    SOCKET s = (SOCKET)RTHandleTableLookup(*pNATHandleTable, fd);
     52    Log6Func(("Looked up %d on %p and returned %d\n", fd, (void *)pNATHandleTable, s));
    5353    return s;
    5454}
     
    6363    }
    6464
    65     Log6Func(("Creating sock %llu on %p\n", uSocket, (void *)pNATHandleTable));
    66     return RTHandleTableAlloc(*pNATHandleTable, (void *)uSocket, pHandle);
     65    int ret = RTHandleTableAlloc(*pNATHandleTable, (void *)uSocket, pHandle);
     66    Log6Func(("Creating sock %llu on %p with handle %d\n", uSocket, (void *)pNATHandleTable, *pHandle));
     67    return ret;
     68}
     69
     70int libslirp_wrap_RTHandleTableFree(int fd)
     71{
     72    if (pNATHandleTable == NULL)
     73        return VERR_INVALID_PARAMETER;
     74
     75    void *ret = RTHandleTableFree(*pNATHandleTable, fd);
     76    Log6Func(("Freeing sock %d on %p\n", fd, (void *)pNATHandleTable));
     77    if (ret)
     78        return VINF_SUCCESS;
     79
     80    return VERR_INVALID_PARAMETER;
    6781}
    6882
  • trunk/src/libs/libslirp-4.8.0/src/nathandletable.h

    r105667 r108816  
    5959extern PRTHANDLETABLE pNATHandleTable;
    6060
     61/**
     62 * Looks up a SOCKET handle by the integer handle used by libslirp.
     63 *
     64 * @returns actual SOCKET handle used by Windows
     65 * @param   fd            Integer handle used internally by libslirp.
     66 */
    6167SOCKET libslirp_wrap_RTHandleTableLookup(int fd);
    6268
    63 int libslirp_wrap_RTHandleTableAlloc(SOCKET, uint32_t *);
     69/**
     70 * Allocates an integer handle from a SOCKET handle for use libslirp.
     71 *
     72 * @returns VBox status code
     73 * @param   s            SOCKET handle from Windows.
     74 *                       Typically from a socket() call.
     75 * @param   h            Return param. Integer handle from table.
     76 */
     77int libslirp_wrap_RTHandleTableAlloc(SOCKET s, uint32_t *h);
     78
     79/**
     80 * Frees entry from lookup table.
     81 *
     82 * @returns VBox status code
     83 * @param   fd            Integer handle used internally by libslirp.
     84 */
     85int libslirp_wrap_RTHandleTableFree(int fd);
    6486
    6587#ifdef __cplusplus
  • trunk/src/libs/libslirp-4.8.0/src/util.c

    r105533 r108816  
    199199
    200200    ret = closesocket(s);
     201
     202    if (ret == SOCKET_ERROR)
     203    {
     204        int iError = WSAGetLastError();
     205        LogFunc(("SOCKET CLOSE ERROR: Handle %d, discovered to be SOCKET %d, \
     206                failed to close with error: %d\n", fd, s, iError));
     207        return ret;
     208    }
     209
     210    ret = libslirp_wrap_RTHandleTableFree(fd);
     211    if (!RT_SUCCESS(ret))
     212    {
     213        Log3Func(("Handle free error: Handle %d which was really %d", fd, s));
     214        return VERR_INVALID_PARAMETER;
     215    }
    201216#else
    202217    ret = closesocket(fd);
    203 #endif
    204     if (ret < 0) {
    205         errno = socket_error();
    206     }
     218    if (ret < 0) {
     219        errno = socket_error();
     220    }
     221#endif
    207222    return ret;
    208223}
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