[gnome-sudoku/qqwing] Don't mix new and free()



commit d5e5d965800c39a20fe42a18f84b160f2b948dbe
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Tue Aug 5 21:06:49 2014 -0500

    Don't mix new and free()
    
    This is undefined behavior

 lib/qqwing-wrapper.cpp |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
---
diff --git a/lib/qqwing-wrapper.cpp b/lib/qqwing-wrapper.cpp
index 77c4d8a..8fba300 100644
--- a/lib/qqwing-wrapper.cpp
+++ b/lib/qqwing-wrapper.cpp
@@ -22,6 +22,7 @@ using namespace std;
 
 /*
  * Generate a symmetric puzzle of specified difficulty.
+ * The result must be freed with g_free() or free().
  */
 int* qqwing_generate_puzzle(int difficulty)
 {
@@ -46,7 +47,8 @@ int* qqwing_generate_puzzle(int difficulty)
         g_error("Could not generate puzzle of specified difficulty. I tried so hard. Please report at 
bugzilla.gnome.org.");
 
     const int* original = board.getPuzzle();
-    int* copy = new int[BOARD_SIZE];
+    // Will be deleted by Vala using g_free(), so the new operator is not safe.
+    int* copy = g_new(int, BOARD_SIZE);
     std::copy(original, &original[BOARD_SIZE], copy);
     return copy;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]