CPU/Cache: Fix some errors exposed by valgrind
authorAli Saidi <Ali.Saidi@ARM.com>
Thu, 30 Sep 2010 14:35:19 +0000 (09:35 -0500)
committerAli Saidi <Ali.Saidi@ARM.com>
Thu, 30 Sep 2010 14:35:19 +0000 (09:35 -0500)
src/cpu/simple/timing.cc
src/mem/packet.hh

index 7b45822d6b25f20d28930a511d35545f3bb6c807..2eb5b432bfdd832c2202167563cd20623fcdc065 100644 (file)
@@ -274,7 +274,7 @@ TimingSimpleCPU::sendData(RequestPtr req, uint8_t *data, uint64_t *res,
 {
     PacketPtr pkt;
     buildPacket(pkt, req, read);
-    pkt->dataDynamic<uint8_t>(data);
+    pkt->dataDynamicArray<uint8_t>(data);
     if (req->getFlags().isSet(Request::NO_ACCESS)) {
         assert(!dcache_pkt);
         pkt->makeResponse();
@@ -402,7 +402,7 @@ TimingSimpleCPU::buildSplitPacket(PacketPtr &pkt1, PacketPtr &pkt2,
     PacketPtr pkt = new Packet(req, pkt1->cmd.responseCommand(),
                                Packet::Broadcast);
 
-    pkt->dataDynamic<uint8_t>(data);
+    pkt->dataDynamicArray<uint8_t>(data);
     pkt1->dataStatic<uint8_t>(data);
     pkt2->dataStatic<uint8_t>(data + req1->getSize());
 
@@ -602,7 +602,7 @@ TimingSimpleCPU::write(T data, Addr addr, unsigned flags, uint64_t *res)
     if (traceData) {
         traceData->setData(data);
     }
-    T *dataP = new T;
+    T *dataP = (T*) new uint8_t[sizeof(T)];
     *dataP = TheISA::htog(data);
 
     return writeTheseBytes((uint8_t *)dataP, sizeof(T), addr, flags, res);
@@ -674,7 +674,7 @@ TimingSimpleCPU::finishTranslation(WholeTranslationState *state)
         if (state->isPrefetch()) {
             state->setNoFault();
         }
-        delete state->data;
+        delete [] state->data;
         state->deleteReqs();
         translationFault(state->getFault());
     } else {
index 48b80879e6b72ea495e0bde149f394af967bfbe7..41edef8a78a161f09a12a45d9618de51ecdeed25 100644 (file)
@@ -705,7 +705,8 @@ class Packet : public FastAlloc, public Printable
     void
     setData(uint8_t *p)
     {
-        std::memcpy(getPtr<uint8_t>(), p, getSize());
+        if (p != getPtr<uint8_t>())
+            std::memcpy(getPtr<uint8_t>(), p, getSize());
     }
 
     /**