diff --git a/CHANGES b/CHANGES index 875b4bb..e05d43c 100644 --- a/CHANGES +++ b/CHANGES @@ -22,6 +22,10 @@ The following are the changes from calc version 2.14.0.9 to date: Makefile checks if ${hardware} is arm64 and adjusts the location of libraries such as readline and history accordingly. + Pluged a number of memory leaks. + + Fixed a few cases where v_subtype was not properly initialuzed. + The following are the changes from calc version 2.14.0.7 to 2.14.0.8: diff --git a/Makefile.local b/Makefile.local index 6494235..a8014cc 100644 --- a/Makefile.local +++ b/Makefile.local @@ -1 +1,2 @@ # Add below to override Makefile values (using :=) as in: HAVE_STRING_H:= YES +DEBUG= -O0 -g diff --git a/func.c b/func.c index 25b5b54..f969987 100644 --- a/func.c +++ b/func.c @@ -1298,6 +1298,7 @@ f_digit(int count, VALUE **vals) base = _ten_; } res.v_type = V_NUM; + res.v_subtype = V_NOSUBTYPE; res.v_num = qdigit(vals[0]->v_num, vals[1]->v_num->num, base); if (res.v_num == NULL) return error_value(E_DGT3); @@ -1323,6 +1324,7 @@ f_digits(int count, VALUE **vals) base = _ten_; } res.v_type = V_NUM; + res.v_subtype = V_NOSUBTYPE; res.v_num = itoq(qdigits(vals[0]->v_num, base)); return res; } @@ -1346,6 +1348,7 @@ f_places(int count, VALUE **vals) places = qdecplaces(vals[0]->v_num); res.v_type = V_NUM; + res.v_subtype = V_NOSUBTYPE; res.v_num = itoq(places); return res; } @@ -3606,6 +3609,7 @@ f_comb(VALUE *v1, VALUE *v2) copyvalue(v1, &result); decvalue(v1, &tmp1); div.v_type = V_NUM; + div.v_subtype = V_NOSUBTYPE; div.v_num = qlink(&_qtwo_); n--; for (;;) { @@ -9039,6 +9043,7 @@ f_sleep(int count, VALUE **vals) NUMBER *q1, *q2; res.v_type = V_NULL; + res.v_subtype = V_NOSUBTYPE; #if !defined(_WIN32) if (count > 0) { if (vals[0]->v_type != V_NUM || qisneg(vals[0]->v_num)) diff --git a/listfunc.c b/listfunc.c index 51bae22..3977751 100644 --- a/listfunc.c +++ b/listfunc.c @@ -161,7 +161,7 @@ removelistfirst(LIST *lp, VALUE *vp) } *vp = lp->l_first->e_value; lp->l_first->e_value.v_type = V_NULL; - lp->l_first->e_value.v_type = V_NOSUBTYPE; + lp->l_first->e_value.v_subtype = V_NOSUBTYPE; removelistelement(lp, lp->l_first); } diff --git a/matfunc.c b/matfunc.c index 15e9d15..edfbb1e 100644 --- a/matfunc.c +++ b/matfunc.c @@ -927,6 +927,7 @@ matindices(MATRIX *mp, long index) lp = listalloc(); val.v_type = V_NUM; + val.v_subtype = V_NOSUBTYPE; j = mp->m_dim; while (--j >= 0) { @@ -1068,6 +1069,7 @@ matident(MATRIX *m) for (row = 0; row < rows; row++) { for (col = 0; col < rows; col++) { val->v_type = V_NUM; + val->v_subtype = V_NOSUBTYPE; val->v_num = ((row == col) ? qlink(&_qone_) : qlink(&_qzero_)); val++; @@ -1126,6 +1128,7 @@ matinv(MATRIX *m) else val->v_num = qlink(&_qzero_); val->v_type = V_NUM; + val->v_subtype = V_NOSUBTYPE; val++; } } diff --git a/qfunc.c b/qfunc.c index bd03ba4..cef1ba3 100644 --- a/qfunc.c +++ b/qfunc.c @@ -683,6 +683,7 @@ qdigit(NUMBER *q, ZVALUE dpos, ZVALUE base) return qlink(&_qzero_); k = zfacrem(q->num, base, &N); if (k == 0) { + zfree(N); k = zgcdrem(q->den, base, &D); if (k > 0) { zequo(q->den, D, &A); diff --git a/qtrans.c b/qtrans.c index 2da35ac..baadb05 100644 --- a/qtrans.c +++ b/qtrans.c @@ -1129,6 +1129,7 @@ qln(NUMBER *q, NUMBER *epsilon) sum.sign = neg; if (k + n >= m) { zshift(sum, n - m, &qtmp->num); + zfree(sum); } else { if (k) { zshift(sum, -k, &qtmp->num); diff --git a/seed.c b/seed.c index 7509958..4ec40d1 100644 --- a/seed.c +++ b/seed.c @@ -373,6 +373,7 @@ pseudo_seed(void) * We do care (that much) if these calls fail. We do not * need to process any data in the 'sdata' structure. */ + memset(&sdata, 0, sizeof(sdata)); #if defined(HAVE_GETTIME) # if defined(CLOCK_SGI_CYCLE) (void) clock_gettime(CLOCK_SGI_CYCLE, &sdata.sgi_cycle); diff --git a/zfunc.c b/zfunc.c index 61181b6..3906c04 100644 --- a/zfunc.c +++ b/zfunc.c @@ -1439,6 +1439,8 @@ zlog10(ZVALUE z, BOOL *was_10_power) if (was_10_power != NULL) { *was_10_power = TRUE; } + zfree(pow10); + zfree(temp); return power; /* ignore this entry if we went too large */ @@ -1452,6 +1454,7 @@ zlog10(ZVALUE z, BOOL *was_10_power) pow10 = temp; } } + zfree(pow10); return power; } @@ -1647,8 +1650,10 @@ zgcdrem(ZVALUE z1, ZVALUE z2, ZVALUE *res) } zgcd(z1, z2, &tmp1); - if (zisunit(tmp1) || ziszero(tmp1)) + if (zisunit(tmp1) || ziszero(tmp1)) { + zfree(tmp1); return 0; + } zequo(z1, tmp1, &tmp2); count = 1; z1 = tmp2; @@ -1668,6 +1673,7 @@ zgcdrem(ZVALUE z1, ZVALUE z2, ZVALUE *res) zfree(z2); z2 = tmp1; } + zfree(z2); *res = z1; return count; }