changeset 90dd57ca9a7e in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=90dd57ca9a7e
description:
        Fix: Address a few minor issues identified by cppcheck

        This patch addresses a number of smaller issues identified by the code
        inspection utility cppcheck. There are a number of identified leaks in
        the arm/linux/system.cc (although the function only get's called once
        so it is not a major problem), a few deletes in dev/x86/i8042.cc that
        were not array deletes, and sprintfs where the character array had one
        element less than needed. In the IIC tags there was a function
        allocating an array of longs which is in fact never used.

diffstat:

 src/arch/arm/linux/system.cc        |  35 ++++++++++++++++++---------------
 src/cpu/legiontrace.cc              |   2 +-
 src/dev/x86/i8042.cc                |   8 +++---
 src/mem/cache/tags/iic_repl/gen.cc  |  39 -------------------------------------
 src/mem/cache/tags/iic_repl/gen.hh  |   7 ------
 src/mem/cache/tags/iic_repl/repl.hh |   7 ------
 6 files changed, 24 insertions(+), 74 deletions(-)

diffs (197 lines):

diff -r a31a1243a3ed -r 90dd57ca9a7e src/arch/arm/linux/system.cc
--- a/src/arch/arm/linux/system.cc      Mon Oct 15 08:12:21 2012 -0400
+++ b/src/arch/arm/linux/system.cc      Mon Oct 15 08:12:23 2012 -0400
@@ -154,40 +154,43 @@
             warn("DTB file specified, but no device tree support in kernel\n");
         }
 
-        AtagCore *ac = new AtagCore;
-        ac->flags(1); // read-only
-        ac->pagesize(8192);
-        ac->rootdev(0);
+        AtagCore ac;
+        ac.flags(1); // read-only
+        ac.pagesize(8192);
+        ac.rootdev(0);
 
         AddrRangeList atagRanges = physmem.getConfAddrRanges();
         if (atagRanges.size() != 1) {
             fatal("Expected a single ATAG memory entry but got %d\n",
                   atagRanges.size());
         }
-        AtagMem *am = new AtagMem;
-        am->memSize(atagRanges.begin()->size());
-        am->memStart(atagRanges.begin()->start);
+        AtagMem am;
+        am.memSize(atagRanges.begin()->size());
+        am.memStart(atagRanges.begin()->start);
 
-        AtagCmdline *ad = new AtagCmdline;
-        ad->cmdline(params()->boot_osflags);
+        AtagCmdline ad;
+        ad.cmdline(params()->boot_osflags);
 
-        DPRINTF(Loader, "boot command line %d bytes: %s\n", ad->size() <<2, 
params()->boot_osflags.c_str());
+        DPRINTF(Loader, "boot command line %d bytes: %s\n",
+                ad.size() <<2, params()->boot_osflags.c_str());
 
-        AtagNone *an = new AtagNone;
+        AtagNone an;
 
-        uint32_t size = ac->size() + am->size() + ad->size() + an->size();
+        uint32_t size = ac.size() + am.size() + ad.size() + an.size();
         uint32_t offset = 0;
         uint8_t *boot_data = new uint8_t[size << 2];
 
-        offset += ac->copyOut(boot_data + offset);
-        offset += am->copyOut(boot_data + offset);
-        offset += ad->copyOut(boot_data + offset);
-        offset += an->copyOut(boot_data + offset);
+        offset += ac.copyOut(boot_data + offset);
+        offset += am.copyOut(boot_data + offset);
+        offset += ad.copyOut(boot_data + offset);
+        offset += an.copyOut(boot_data + offset);
 
         DPRINTF(Loader, "Boot atags was %d bytes in total\n", size << 2);
         DDUMP(Loader, boot_data, size << 2);
 
         physProxy.writeBlob(params()->atags_addr, boot_data, size << 2);
+
+        delete[] boot_data;
     }
 
     for (int i = 0; i < threadContexts.size(); i++) {
diff -r a31a1243a3ed -r 90dd57ca9a7e src/cpu/legiontrace.cc
--- a/src/cpu/legiontrace.cc    Mon Oct 15 08:12:21 2012 -0400
+++ b/src/cpu/legiontrace.cc    Mon Oct 15 08:12:23 2012 -0400
@@ -536,7 +536,7 @@
                     }
                     if (diffTlb) {
                         printColumnLabels(outs);
-                        char label[8];
+                        char label[9];
                         for (int x = 0; x < 64; x++) {
                             if (shared_data->itb[x] !=
                                     ULL(0xFFFFFFFFFFFFFFFF) ||
diff -r a31a1243a3ed -r 90dd57ca9a7e src/dev/x86/i8042.cc
--- a/src/dev/x86/i8042.cc      Mon Oct 15 08:12:21 2012 -0400
+++ b/src/dev/x86/i8042.cc      Mon Oct 15 08:12:23 2012 -0400
@@ -490,7 +490,7 @@
     }
     arrayParamOut(os, base + ".outBuffer.elts", buffer,
             bufferSize*sizeof(uint8_t));
-    delete buffer;
+    delete[] buffer;
 }
 
 void
@@ -506,7 +506,7 @@
     for (int i = 0; i < bufferSize; ++i) {
         outBuffer.push(buffer[i]);
     }
-    delete buffer;
+    delete[] buffer;
 }
 
 void
@@ -523,7 +523,7 @@
     }
     arrayParamOut(os, base + ".outBuffer.elts", buffer,
             bufferSize*sizeof(uint8_t));
-    delete buffer;
+    delete[] buffer;
     paramOut(os, base + ".status", statusData);
     paramOut(os, base + ".resolution", resolution);
     paramOut(os, base + ".sampleRate", sampleRate);
@@ -543,7 +543,7 @@
     for (int i = 0; i < bufferSize; ++i) {
         outBuffer.push(buffer[i]);
     }
-    delete buffer;
+    delete[] buffer;
     paramIn(cp, section, base + ".status", statusData);
     paramIn(cp, section, base + ".resolution", resolution);
     paramIn(cp, section, base + ".sampleRate", sampleRate);
diff -r a31a1243a3ed -r 90dd57ca9a7e src/mem/cache/tags/iic_repl/gen.cc
--- a/src/mem/cache/tags/iic_repl/gen.cc        Mon Oct 15 08:12:21 2012 -0400
+++ b/src/mem/cache/tags/iic_repl/gen.cc        Mon Oct 15 08:12:23 2012 -0400
@@ -93,45 +93,6 @@
     return 0xffffffff;
 }
 
-unsigned long *
-GenRepl::getNRepl(int n)
-{
-    unsigned long *tmp;
-    GenReplEntry *re;
-    int i;
-    if (!(num_pool_entries>(n-1))) {
-        fatal("Not enough blks available to replace");
-    }
-    num_entries -= n;
-    num_pool_entries -= n;
-    tmp = new unsigned long[n]; /* array of cache_blk pointers */
-    int blk_index = 0;
-    for (i = 0; i < num_pools && blk_index < n; i++) {
-        while (blk_index < n && (re = pools[i].pop())) {
-            // Remove invalidated entries
-            if (!re->valid) {
-                delete re;
-                continue;
-            }
-            if (iic->clearRef(re->tag_ptr)) {
-                pools[(((i+1)== num_pools)? i :i+1)].push(re, misses);
-            }
-            else {
-                tmp[blk_index] = re->tag_ptr;
-                blk_index++;
-                delete re;
-                repl_pool.sample(i);
-            }
-        }
-    }
-    if (blk_index >= n)
-        return tmp;
-    /* search the fresh pool */
-
-    fatal("No N  replacements found");
-    return NULL;
-}
-
 void
 GenRepl::doAdvance(std::list<unsigned long> &demoted)
 {
diff -r a31a1243a3ed -r 90dd57ca9a7e src/mem/cache/tags/iic_repl/gen.hh
--- a/src/mem/cache/tags/iic_repl/gen.hh        Mon Oct 15 08:12:21 2012 -0400
+++ b/src/mem/cache/tags/iic_repl/gen.hh        Mon Oct 15 08:12:23 2012 -0400
@@ -186,13 +186,6 @@
     virtual unsigned long getRepl();
 
     /**
-     * Return an array of N tag pointers to replace.
-     * @param n The number of tag pointer to return.
-     * @return An array of tag pointers to replace.
-     */
-    virtual unsigned long *getNRepl(int n);
-
-    /**
      * Update replacement data
      */
     virtual void doAdvance(std::list<unsigned long> &demoted);
diff -r a31a1243a3ed -r 90dd57ca9a7e src/mem/cache/tags/iic_repl/repl.hh
--- a/src/mem/cache/tags/iic_repl/repl.hh       Mon Oct 15 08:12:21 2012 -0400
+++ b/src/mem/cache/tags/iic_repl/repl.hh       Mon Oct 15 08:12:23 2012 -0400
@@ -79,13 +79,6 @@
     virtual unsigned long getRepl() = 0;
 
     /**
-     * Return an array of N tag pointers to replace.
-     * @param n The number of tag pointer to return.
-     * @return An array of tag pointers to replace.
-     */
-    virtual unsigned long  *getNRepl(int n) = 0;
-
-    /**
      * Update replacement data
      */
     virtual void doAdvance(std::list<unsigned long> &demoted) = 0;
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to