On 2017-03-05 01:40, hbelu...@svn.reactos.org wrote:
+
+    /*
+     * Check whether we actually just retrieved the needed buffer size
+     * because our previous local allocation did fail. If so, allocate
+     * a new buffer and retry again.
+     */
+    if ( (!UnicodeQuerySet) && (*lpdwBufferLength >= sizeof(WSAQUERYSETW)) &&
+         (ErrorCode == SOCKET_ERROR) && (GetLastError() == WSAEFAULT) )

Seems like you'd want to check WSAGetLastError when looking for WSA* error codes.

+    {
+        /* Allocate the buffer we'll use */
+        UnicodeQuerySet = HeapAlloc(WsSockHeap, 0, UnicodeQuerySetSize);
+        if (UnicodeQuerySet)
+        {
+            /* Call the Unicode Function */
+            ErrorCode = WSALookupServiceNextW(hLookup,
+                                              dwControlFlags,
+                                              &UnicodeQuerySetSize,
+                                              UnicodeQuerySet);
+        }
+        /*
+         * Otherwise the allocation failed and we
+         * fall back into the error checks below.
+         */
+    }
+
     if (ErrorCode == ERROR_SUCCESS)
     {
-        /* Not convert to ANSI */
+        /* Now convert back to ANSI */
         ErrorCode = MapUnicodeQuerySetToAnsi(UnicodeQuerySet,
                                              lpdwBufferLength,
                                              lpqsResults);
-        if (ErrorCode != ERROR_SUCCESS) SetLastError(ErrorCode);
+        if (ErrorCode != ERROR_SUCCESS)
+            SetLastError(ErrorCode);
     }
     else
     {
@@ -499,10 +542,11 @@
     }

     /* If we had a local buffer, free it */
-    if (UnicodeQuerySet) HeapFree(WsSockHeap, 0, UnicodeQuerySet);
+    if (UnicodeQuerySet)
+        HeapFree(WsSockHeap, 0, UnicodeQuerySet);

HeapFree(NULL) is fine by the way.


     /* Return to caller */
-    return ErrorCode == ERROR_SUCCESS ? ErrorCode : SOCKET_ERROR;
+    return (ErrorCode == ERROR_SUCCESS) ? ErrorCode : SOCKET_ERROR;
 }


_______________________________________________
Ros-dev mailing list
Ros-dev@reactos.org
http://www.reactos.org/mailman/listinfo/ros-dev

Reply via email to