    if (ret == WS_SUCCESS) {
        DIR_HANDLE* cur = (DIR_HANDLE*)WMALLOC(sizeof(DIR_HANDLE),
                ssh->ctx->heap, DYNTYPE_SFTP);
        if (cur == NULL) {
            WFREE(dirName, ssh->ctx->heap, DYNTYPE_BUFFER);
            return WS_MEMORY_E;
        }
        cur->dir = INVALID_HANDLE_VALUE;
        cur->id[0] = id[0] = idCount[0];
        cur->id[1] = id[1] = idCount[1];
        c32toa(id[0], idFlat);
        c32toa(id[1], idFlat + UINT32_SZ);
        AddAssign64(idCount, 1);
        cur->isEof = 0;
        cur->dirName = dirName; /* take over ownership of buffer */
        cur->next = dirList;
        dirList = cur;

    }
    if (ret == WS_SUCCESS) {
        DIR_HANDLE* cur = (DIR_HANDLE*)WMALLOC(sizeof(DIR_HANDLE),
                ssh->ctx->heap, DYNTYPE_SFTP);
        if (cur == NULL) {
            WFREE(dirName, ssh->ctx->heap, DYNTYPE_BUFFER);
            return WS_MEMORY_E;
        }
        cur->dir = INVALID_HANDLE_VALUE;
        cur->id[0] = id[0] = idCount[0];
        cur->id[1] = id[1] = idCount[1];
        c32toa(id[0], idFlat);
        c32toa(id[1], idFlat + UINT32_SZ);
        AddAssign64(idCount, 1);
        cur->isEof = 0;
        cur->dirName = dirName;  
        cur->next = dirList;
        dirList = cur;

    }