]> git.mdlowis.com Git - projs/tide.git/commitdiff
fixed bad memory handling in view when clearing rows
authorMichael D. Lowis <mike.lowis@gentex.com>
Tue, 3 Jul 2018 17:36:36 +0000 (13:36 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Tue, 3 Jul 2018 17:36:36 +0000 (13:36 -0400)
lib/view.c

index 30168c1ce38a5c6c9ce15d65a0305a8014e4ab5f..0d0cfb7716191ab84d07221509b9603944b0597f 100644 (file)
@@ -51,9 +51,17 @@ static Sel* getsel(View* view) {
 
 static void clear_rows(View* view, size_t startidx) {
     if (view->rows) {
-        for (size_t i = startidx; i < view->nrows; i++)
+        /* Free and clear invalid rows now */
+        for (size_t i = startidx; i < view->nrows; i++) {
             free(view->rows[i]);
-        view->rows = realloc(view->rows, startidx);
+            view->rows[i] = NULL;
+        }
+        /* grow row array if needed */
+        if (startidx > view->nrows)
+            view->rows = realloc(view->rows, startidx);
+        /* zero out newly created slots */
+        for (size_t i = view->nrows; i < startidx; i++)
+            view->rows[i] = NULL;
         view->nrows = startidx;
     }
 }