Index: /trunk/psLib/src/dataManip/psMatrixVectorArithmetic.c
===================================================================
--- /trunk/psLib/src/dataManip/psMatrixVectorArithmetic.c	(revision 1646)
+++ /trunk/psLib/src/dataManip/psMatrixVectorArithmetic.c	(revision 1647)
@@ -30,6 +30,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-08-14 01:31:43 $
+ *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-08-27 23:29:36 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -509,4 +509,14 @@
     }
 
+    // Automtically free psScalar types, since they are usually allocated in the argument list when this
+    // function is called, provided that the input is not the output.
+    if(psType1->dimen==PS_DIMEN_SCALAR && in1!=out) {
+        psFree(in1);
+    }
+
+    if(psType2->dimen==PS_DIMEN_SCALAR && in2!=out) {
+        psFree(in2);
+    }
+
     return out;
 }
@@ -517,6 +527,6 @@
     ps##TYPE *o = NULL;                                                                                      \
     ps##TYPE *i1 = NULL;                                                                                     \
-    o  = &((psScalar* )OUT)->data.TYPE;                                                                       \
-    i1 = &((psScalar* )IN)->data.TYPE;                                                                        \
+    o  = &((psScalar* )OUT)->data.TYPE;                                                                      \
+    i1 = &((psScalar* )IN)->data.TYPE;                                                                       \
     *o = OP;                                                                                                 \
 }
@@ -530,12 +540,12 @@
     ps##TYPE *o = NULL;                                                                                      \
     ps##TYPE *i1 = NULL;                                                                                     \
-    nIn = ((psVector* )IN)->n;                                                                                \
-    nOut = ((psVector* )OUT)->n;                                                                              \
+    nIn = ((psVector* )IN)->n;                                                                               \
+    nOut = ((psVector* )OUT)->n;                                                                             \
     if(nIn != nOut) {                                                                                        \
         psError(__func__, ": Inconsistent element count: %d vs %d", nIn, nOut);                              \
         return OUT;                                                                                          \
     }                                                                                                        \
-    o  = ((psVector* )OUT)->data.TYPE;                                                                        \
-    i1 = ((psVector* )IN)->data.TYPE;                                                                         \
+    o  = ((psVector* )OUT)->data.TYPE;                                                                       \
+    i1 = ((psVector* )IN)->data.TYPE;                                                                        \
     for(i = 0; i < nIn; i++, o++, i1++) {                                                                    \
         *o = OP;                                                                                             \
@@ -554,8 +564,8 @@
     ps##TYPE *o = NULL;                                                                                      \
     ps##TYPE *i1 = NULL;                                                                                     \
-    numRowsIn = ((psImage* )IN)->numRows;                                                                     \
-    numColsIn = ((psImage* )IN)->numCols;                                                                     \
-    numRowsOut = ((psImage* )OUT)->numRows;                                                                   \
-    numColsOut = ((psImage* )OUT)->numCols;                                                                   \
+    numRowsIn = ((psImage* )IN)->numRows;                                                                    \
+    numColsIn = ((psImage* )IN)->numCols;                                                                    \
+    numRowsOut = ((psImage* )OUT)->numRows;                                                                  \
+    numColsOut = ((psImage* )OUT)->numCols;                                                                  \
     if(numRowsIn!=numRowsOut || numColsIn!=numColsOut) {                                                     \
         psError(__func__, ": Inconsistent element count: numRows: %d vs %d numCols: %d vs %d", numRowsIn,    \
@@ -564,6 +574,6 @@
     }                                                                                                        \
     for(j = 0; j < numRowsIn; j++) {                                                                         \
-        o  = ((psImage* )OUT)->data.TYPE[j];                                                                  \
-        i1 = ((psImage* )IN)->data.TYPE[j];                                                                   \
+        o  = ((psImage* )OUT)->data.TYPE[j];                                                                 \
+        i1 = ((psImage* )IN)->data.TYPE[j];                                                                  \
         for(i = 0; i < numColsIn; i++, o++, i1++) {                                                          \
             *o = OP;                                                                                         \
@@ -791,4 +801,10 @@
     }
 
+    // Automtically free psScalar types, since they are usually allocated in the argument list when this
+    // function is called, provided that the input is not the output.
+    if(psTypeIn->dimen==PS_DIMEN_SCALAR && in!=out) {
+        psFree(in);
+    }
+
     return out;
 }
Index: /trunk/psLib/test/dataManip/tst_psMatrixVectorArithmetic01.c
===================================================================
--- /trunk/psLib/test/dataManip/tst_psMatrixVectorArithmetic01.c	(revision 1646)
+++ /trunk/psLib/test/dataManip/tst_psMatrixVectorArithmetic01.c	(revision 1647)
@@ -10,6 +10,6 @@
  *  @author  Ross Harman, MHPCC
  *
- *  @version $Revision: 1.2 $  $Name: not supported by cvs2svn $
- *  @date  $Date: 2004-08-06 22:34:06 $
+ *  @version $Revision: 1.3 $  $Name: not supported by cvs2svn $
+ *  @date  $Date: 2004-08-27 23:29:25 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -171,5 +171,5 @@
         PRINT_MATRIX(outImage,TYPE);                                                                         \
         PRINT_SCALAR(inScalar,TYPE);                                                                         \
-        outImage = (psImage*)psBinaryOp(outImage, outImage, #OP, inScalar);                                  \
+        outImage = (psImage*)psBinaryOp(outImage, outImage, #OP, psScalarCopy(inScalar));                    \
         printf("Output:\n");                                                                                 \
         PRINT_MATRIX(outImage,TYPE);                                                                         \
