Index: trunk/src/VBox/Devices/Network/DevVirtioNet.cpp
===================================================================
--- trunk/src/VBox/Devices/Network/DevVirtioNet.cpp	(revision 24622)
+++ trunk/src/VBox/Devices/Network/DevVirtioNet.cpp	(revision 24623)
@@ -225,7 +225,4 @@
 PDMBOTHCBDECL(void)     vnetReset(void *pState);
 PDMBOTHCBDECL(void)     vnetReady(void *pState);
-#ifdef DEBUG
-static const char *vnetGetQueueName(void *pvState, PVQUEUE pQueue);
-#endif /* DEBUG */
 RT_C_DECLS_END
 
@@ -982,8 +979,7 @@
               pState->Queues[i].uNextUsedIndex,
               pState->Queues[i].uPageNumber));
-
 }
 #else
-#define vpciDumpState(x, s)
+# define vpciDumpState(x, s)  do {} while (0)
 #endif
 
@@ -1266,5 +1262,4 @@
     uint16_t uStatus;
 };
-
 AssertCompileMemberOffset(struct VNetPCIConfig, uStatus, 6);
 
@@ -1290,25 +1285,29 @@
     uint32_t    padding;
 #endif
-    PTMTIMERR3  pLinkUpTimer;                             /**< Link Up(/Restore) Timer. */
+
+    /** transmit buffer */
+    R3PTRTYPE(uint8_t*)     pTxBuf;
+    /**< Link Up(/Restore) Timer. */
+    PTMTIMERR3              pLinkUpTimer; 
 
     /** PCI config area holding MAC address as well as TBD. */
-    struct VNetPCIConfig config;
+    struct VNetPCIConfig    config;
     /** MAC address obtained from the configuration. */
-    RTMAC       macConfigured;
+    RTMAC                   macConfigured;
     /** True if physical cable is attached in configuration. */
-    bool        fCableConnected;
+    bool                    fCableConnected;
 
     /** Number of packet being sent/received to show in debug log. */
-    uint32_t    u32PktNo;
+    uint32_t                u32PktNo;
 
     /** Locked state -- no state alteration possible. */
-    bool        fLocked;
+    bool                    fLocked;
 
     /** N/A: */
-    bool volatile fMaybeOutOfSpace;
-
-    R3PTRTYPE(PVQUEUE) pRxQueue;
-    R3PTRTYPE(PVQUEUE) pTxQueue;
-    R3PTRTYPE(PVQUEUE) pCtlQueue;
+    bool volatile           fMaybeOutOfSpace;
+
+    R3PTRTYPE(PVQUEUE)      pRxQueue;
+    R3PTRTYPE(PVQUEUE)      pTxQueue;
+    R3PTRTYPE(PVQUEUE)      pCtlQueue;
     /* Receive-blocking-related fields ***************************************/
 
@@ -1318,12 +1317,12 @@
     /* Statistic fields ******************************************************/
 
-    STAMCOUNTER                         StatReceiveBytes;
-    STAMCOUNTER                         StatTransmitBytes;
+    STAMCOUNTER             StatReceiveBytes;
+    STAMCOUNTER             StatTransmitBytes;
 #if defined(VBOX_WITH_STATISTICS)
-    STAMPROFILEADV                      StatReceive;
-    STAMPROFILEADV                      StatTransmit;
-    STAMPROFILEADV                      StatTransmitSend;
-    STAMPROFILE                         StatRxOverflow;
-    STAMCOUNTER                         StatRxOverflowWakeup;
+    STAMPROFILEADV          StatReceive;
+    STAMPROFILEADV          StatTransmit;
+    STAMPROFILEADV          StatTransmitSend;
+    STAMPROFILE             StatRxOverflow;
+    STAMCOUNTER             StatRxOverflowWakeup;
 #endif /* VBOX_WITH_STATISTICS */
 
@@ -1338,6 +1337,6 @@
 struct VNetHdr
 {
-    uint8_t u8Flags;
-    uint8_t u8GSOType;
+    uint8_t  u8Flags;
+    uint8_t  u8GSOType;
     uint16_t u16HdrLen;
     uint16_t u16GSOSize;
@@ -1347,4 +1346,5 @@
 typedef struct VNetHdr VNETHDR;
 typedef VNETHDR *PVNETHDR;
+AssertCompileSize(VNETHDR, 10);
 
 AssertCompileMemberOffset(VNETSTATE, VPCI, 0);
@@ -1800,13 +1800,4 @@
         else
         {
-            uint8_t *pFrame = (uint8_t *)RTMemAllocZ(VNET_MAX_FRAME_SIZE);
-            if (!pFrame)
-            {
-                Log(("%s vnetQueueTransmit: Failed to allocate %u bytes.\n",
-                     INSTANCE(pState), VNET_MAX_FRAME_SIZE));
-                vqueueElemFree(&elem);
-                break; /* For now we simply ignore the header, but it must be there anyway! */
-            }
-
             /* Assemble a complete frame. */
             for (unsigned int i = 1; i < elem.nOut && uOffset < VNET_MAX_FRAME_SIZE; i++)
@@ -1819,12 +1810,11 @@
                 }
                 PDMDevHlpPhysRead(pState->VPCI.CTX_SUFF(pDevIns), elem.aSegsOut[i].addr,
-                                  pFrame + uOffset, uSize);
+                                  pState->pTxBuf + uOffset, uSize);
                 uOffset += uSize;
             }
             STAM_PROFILE_ADV_START(&pState->StatTransmitSend, a);
-            int rc = pState->pDrv->pfnSend(pState->pDrv, pFrame, uOffset);
+            int rc = pState->pDrv->pfnSend(pState->pDrv, pState->pTxBuf, uOffset);
             STAM_PROFILE_ADV_STOP(&pState->StatTransmitSend, a);
             STAM_REL_COUNTER_ADD(&pState->StatTransmitBytes, uOffset);
-            RTMemFree(pFrame);
         }
         vqueuePut(&pState->VPCI, pQueue, &elem, sizeof(VNETHDR) + uOffset);
@@ -1968,6 +1958,6 @@
     rc = SSMR3GetMem(pSSM, &macConfigured, sizeof(macConfigured));
     AssertRCReturn(rc, rc);
-    if (   memcmp(&macConfigured, &pState->macConfigured, sizeof(macConfigured))
-           && (uPass == 0 || !PDMDevHlpVMTeleportedAndNotFullyResumedYet(pDevIns)) )
+    if (memcmp(&macConfigured, &pState->macConfigured, sizeof(macConfigured))
+        && (uPass == 0 || !PDMDevHlpVMTeleportedAndNotFullyResumedYet(pDevIns)))
         LogRel(("%s: The mac address differs: config=%RTmac saved=%RTmac\n", INSTANCE(pState), &pState->macConfigured, &macConfigured));
 
@@ -2051,4 +2041,8 @@
     pState->INetworkConfig.pfnSetLinkState   = vnetSetLinkState;
 
+    pState->pTxBuf = (uint8_t *)RTMemAllocZ(VNET_MAX_FRAME_SIZE);
+    AssertMsgReturn(pState->pTxBuf, 
+                    ("Cannot allocate TX buffer for virtio-net device\n"), VERR_NO_MEMORY);
+
     /* Register save/restore state handlers. */
     rc = PDMDevHlpSSMRegisterEx(pDevIns, VNET_SAVEDSTATE_VERSION, sizeof(VNETSTATE), NULL,
@@ -2057,5 +2051,5 @@
                                 vnetLoadPrep, vnetLoadExec, NULL);
     if (RT_FAILURE(rc))
-    return rc;
+        return rc;
 
     /* Create the RX notifier signaller. */
@@ -2135,4 +2129,10 @@
         RTSemEventDestroy(pState->hEventMoreRxDescAvail);
         pState->hEventMoreRxDescAvail = NIL_RTSEMEVENT;
+    }
+
+    if (pState->pTxBuf)
+    {
+        RTMemFree(pState->pTxBuf);
+        pState->pTxBuf = NULL;
     }
 
@@ -2348,3 +2348,2 @@
 #endif /* IN_RING3 */
 #endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
-
