diff options
author | zimmerma <zimmerma@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2009-04-02 08:47:18 +0000 |
---|---|---|
committer | zimmerma <zimmerma@211d60ee-9f03-0410-a15a-8952a2c7a4e4> | 2009-04-02 08:47:18 +0000 |
commit | e12e1242c028482a1add89e0b1b914de11b0bbf7 (patch) | |
tree | f2fda6b53c129b47aaa48e0dcc57b46b49286c3d | |
parent | e4ff245859293937f081a633c2671eda91848d48 (diff) | |
download | mpc-e12e1242c028482a1add89e0b1b914de11b0bbf7.tar.gz |
[norm.c] fixed memory leak (found by valgrind)
[inp_str.c] fixed bug report found with -D_FORTIFY_SOURCE=2
(http://lists.gforge.inria.fr/pipermail/mpc-discuss/2009-April/000182.html)
[random.c] fixed memory leak (found by valgrind)
[Makefile.am] indentation
[README.dev] added use of valgrind before doing a release
git-svn-id: svn://scm.gforge.inria.fr/svn/mpc/trunk@530 211d60ee-9f03-0410-a15a-8952a2c7a4e4
-rw-r--r-- | README.dev | 1 | ||||
-rw-r--r-- | src/inp_str.c | 11 | ||||
-rw-r--r-- | src/norm.c | 6 | ||||
-rw-r--r-- | tests/Makefile.am | 16 | ||||
-rw-r--r-- | tests/random.c | 1 |
5 files changed, 21 insertions, 14 deletions
@@ -14,6 +14,7 @@ Required versions: Creating a new release ---------------------- + 0) Run all tests with valgrind and check no memory leak remains. 1) Check the version number in configure.ac ("AC_INIT (mpc, _version_...)"), INSTALL, src/get_version.c, src/mpc.h (remove suffix "-dev" in MPC_VERSION_STRING) and Makefile.vc. diff --git a/src/inp_str.c b/src/inp_str.c index cb34c6e..5c5db31 100644 --- a/src/inp_str.c +++ b/src/inp_str.c @@ -1,6 +1,6 @@ /* mpc_inp_str -- Input a complex number from a given stream. -Copyright (C) 2009 Andreas Enge, Philippe Th\'eveny, Paul Zimmermann. +Copyright (C) 2009 Andreas Enge, Philippe Th\'eveny, Paul Zimmermann This file is part of the MPC Library. @@ -80,6 +80,7 @@ extract_string (FILE *stream) size_t nread = 0; size_t strsize = 100; char *str = mpc_alloc_str (strsize); + size_t lenstr; c = getc (stream); while (c != EOF && c != '\n' @@ -101,6 +102,8 @@ extract_string (FILE *stream) if (nread == 0) return str; + lenstr = nread; + if (c == '(') { size_t n; char *suffix; @@ -127,7 +130,7 @@ extract_string (FILE *stream) strsize = nread + 1; } - n = sprintf (str, "%s(%s", str, suffix); + n = lenstr + sprintf (str + lenstr, "(%s", suffix); MPC_ASSERT (n == nread); c = getc (stream); @@ -151,7 +154,9 @@ extract_string (FILE *stream) int -mpc_inp_str (mpc_ptr rop, FILE *stream, size_t *read, int base, mpc_rnd_t rnd_mode) { +mpc_inp_str (mpc_ptr rop, FILE *stream, size_t *read, int base, +mpc_rnd_t rnd_mode) +{ size_t white, nread = 0; int inex = -1; int c; @@ -30,15 +30,15 @@ mpc_norm (mpfr_ptr a, mpc_srcptr b, mp_rnd_t rnd) prec = MPFR_PREC(a); - mpfr_init (u); - mpfr_init (v); - /* handling of special values; consistent with abs in that norm = abs^2; so norm (+-inf, nan) = norm (nan, +-inf) = +inf */ if ( (mpfr_nan_p (MPC_RE (b)) || mpfr_nan_p (MPC_IM (b))) || (mpfr_inf_p (MPC_RE (b)) || mpfr_inf_p (MPC_IM (b)))) return mpc_abs (a, b, rnd); + mpfr_init (u); + mpfr_init (v); + if (!mpfr_zero_p(MPC_RE(b)) && !mpfr_zero_p(MPC_IM(b)) && 2 * SAFE_ABS (mp_exp_t, MPFR_EXP (MPC_RE (b)) - MPFR_EXP (MPC_IM (b))) > (mp_exp_t)prec) diff --git a/tests/Makefile.am b/tests/Makefile.am index 99b73da..77494a8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -3,19 +3,19 @@ AM_CFLAGS=@WARNINGCFLAGS@ AM_CPPFLAGS = -I$(top_srcdir)/src LDADD = libmpc-tests.la $(top_builddir)/src/libmpc.la -check_PROGRAMS = tio_str tabs tadd tadd_fr tadd_ui targ tconj tcos tcosh tdiv \ -tdiv_2exp tdiv_fr tdiv_ui texp tfr_div tfr_sub tget_version timag tlog tmul \ -tmul_2exp tmul_fr tmul_i tmul_si tmul_ui tneg tnorm tprec tproj treal tset \ -tsin tsinh tsqr tsqrt tstrtoc tsub tsub_fr tsub_ui ttan ttanh tui_div \ +check_PROGRAMS = tio_str tabs tadd tadd_fr tadd_ui targ tconj tcos tcosh tdiv \ +tdiv_2exp tdiv_fr tdiv_ui texp tfr_div tfr_sub tget_version timag tlog tmul \ +tmul_2exp tmul_fr tmul_i tmul_si tmul_ui tneg tnorm tprec tproj treal tset \ +tsin tsinh tsqr tsqrt tstrtoc tsub tsub_fr tsub_ui ttan ttanh tui_div \ tui_ui_sub treimref check_LTLIBRARIES=libmpc-tests.la -libmpc_tests_la_SOURCES=mpc-tests.h random.c tgeneric.c read_data.c \ +libmpc_tests_la_SOURCES=mpc-tests.h random.c tgeneric.c read_data.c \ comparisons.c -EXTRA_DIST = abs.dat add.dat add_fr.dat arg.dat conj.dat cos.dat cosh.dat \ -div.dat div_fr.dat exp.dat fr_div.dat fr_sub.dat inp_str.dat log.dat mul.dat \ -mul_fr.dat neg.dat norm.dat proj.dat sin.dat sinh.dat sqr.dat sqrt.dat \ +EXTRA_DIST = abs.dat add.dat add_fr.dat arg.dat conj.dat cos.dat cosh.dat \ +div.dat div_fr.dat exp.dat fr_div.dat fr_sub.dat inp_str.dat log.dat mul.dat \ +mul_fr.dat neg.dat norm.dat proj.dat sin.dat sinh.dat sqr.dat sqrt.dat \ strtoc.dat sub.dat sub_fr.dat tan.dat tanh.dat TESTS = $(check_PROGRAMS) diff --git a/tests/random.c b/tests/random.c index a28c464..cfd7260 100644 --- a/tests/random.c +++ b/tests/random.c @@ -96,6 +96,7 @@ test_end (void) rands_initialized = 0; gmp_randclear (rands); } + mpfr_free_cache (); } /* wrapper for gmp_urandomb_ui, which did not exist in old versions of GMP */ |