Commit : Memory Leaks Plugged#

This commit is contained in:
Rafat Hussain 2016-03-08 06:40:13 +05:30
parent 1c0644364a
commit 4075ae5bc8
4 changed files with 56 additions and 31 deletions

View File

@ -204,5 +204,7 @@ void conv_fft(const conv_object obj,fft_type *inp1,fft_type *inp2,fft_type *oup)
void free_conv(conv_object object) {
free_real_fft(object->fobj);
free_real_fft(object->iobj);
free(object);
}

View File

@ -106,6 +106,7 @@ void fft_c2r_exec(fft_real_object obj,fft_data *inp,fft_type *oup) {
}
void free_real_fft(fft_real_object object) {
free_fft(object->cobj);
free(object);
}

View File

@ -3038,7 +3038,7 @@ int filtlength(const char* name) {
}
else if (len > 2 && strstr(name, "db") != NULL)
{
new_str = malloc(sizeof(char)*(len-2 + 1));
new_str = (char*)malloc(sizeof(char)*(len-2 + 1));
for (i = 2; i < len + 1; i++)
new_str[i - 2] = name[i];
@ -3158,7 +3158,7 @@ int filtlength(const char* name) {
}
else if (len > 4 && strstr(name, "coif") != NULL)
{
new_str = malloc(sizeof(char)*(len - 4 + 1));
new_str = (char*)malloc(sizeof(char)*(len - 4 + 1));
for (i = 4; i < len + 1; i++)
new_str[i - 4] = name[i];
@ -3174,7 +3174,7 @@ int filtlength(const char* name) {
}
else if (len > 3 && strstr(name, "sym") != NULL)
{
new_str = malloc(sizeof(char)*(len - 3 + 1));
new_str = (char*)malloc(sizeof(char)*(len - 3 + 1));
for (i = 3; i < len + 1; i++)
new_str[i - 3] = name[i];
@ -3206,7 +3206,7 @@ void qmf_wrev(const double *in, int N, double *out)
{
int count = 0;
double *sigOutTemp;
sigOutTemp = malloc(N*sizeof(double));
sigOutTemp = (double*)malloc(N*sizeof(double));
qmf_even(in, N, sigOutTemp);
copy_reverse(sigOutTemp, N, out);
@ -3764,7 +3764,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
}
else if (!strcmp(name,"coif1")){
double *coeffTemp;
coeffTemp = malloc(N*sizeof(double));
coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif1, N, coeffTemp);
for (i = 0; i < N; ++i) {
@ -3781,7 +3781,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
}
else if (!strcmp(name,"coif2")){
double *coeffTemp;
coeffTemp = malloc(N*sizeof(double));
coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif2, N, coeffTemp);
for (i = 0; i < N; ++i) {
@ -3798,7 +3798,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
}
else if (!strcmp(name,"coif3")){
double *coeffTemp;
coeffTemp = malloc(N*sizeof(double));
coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif3, N, coeffTemp);
for (i = 0; i < N; ++i) {
@ -3815,7 +3815,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
}
else if (!strcmp(name,"coif4")){
double *coeffTemp;
coeffTemp = malloc(N*sizeof(double));
coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif4, N, coeffTemp);
for (i = 0; i < N; ++i) {
@ -3832,7 +3832,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
}
else if (!strcmp(name,"coif5")){
double *coeffTemp;
coeffTemp = malloc(N*sizeof(double));
coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif5, N, coeffTemp);
for (i = 0; i < N; ++i) {
@ -3849,7 +3849,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
}
else if (!strcmp(name, "coif6")){
double *coeffTemp;
coeffTemp = malloc(N*sizeof(double));
coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif6, N, coeffTemp);
for (i = 0; i < N; ++i) {
@ -3866,7 +3866,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
}
else if (!strcmp(name, "coif7")){
double *coeffTemp;
coeffTemp = malloc(N*sizeof(double));
coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif7, N, coeffTemp);
for (i = 0; i < N; ++i) {
@ -3883,7 +3883,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
}
else if (!strcmp(name, "coif8")){
double *coeffTemp;
coeffTemp = malloc(N*sizeof(double));
coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif8, N, coeffTemp);
for (i = 0; i < N; ++i) {
@ -3900,7 +3900,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
}
else if (!strcmp(name, "coif9")){
double *coeffTemp;
coeffTemp = malloc(N*sizeof(double));
coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif9, N, coeffTemp);
for (i = 0; i < N; ++i) {
@ -3917,7 +3917,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
}
else if (!strcmp(name, "coif10")){
double *coeffTemp;
coeffTemp = malloc(N*sizeof(double));
coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif10, N, coeffTemp);
for (i = 0; i < N; ++i) {
@ -3934,7 +3934,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
}
else if (!strcmp(name, "coif11")){
double *coeffTemp;
coeffTemp = malloc(N*sizeof(double));
coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif11, N, coeffTemp);
for (i = 0; i < N; ++i) {
@ -3951,7 +3951,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
}
else if (!strcmp(name, "coif12")){
double *coeffTemp;
coeffTemp = malloc(N*sizeof(double));
coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif12, N, coeffTemp);
for (i = 0; i < N; ++i) {
@ -3968,7 +3968,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
}
else if (!strcmp(name, "coif13")){
double *coeffTemp;
coeffTemp = malloc(N*sizeof(double));
coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif13, N, coeffTemp);
for (i = 0; i < N; ++i) {
@ -3985,7 +3985,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
}
else if (!strcmp(name, "coif14")){
double *coeffTemp;
coeffTemp = malloc(N*sizeof(double));
coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif14, N, coeffTemp);
for (i = 0; i < N; ++i) {
@ -4002,7 +4002,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
}
else if (!strcmp(name, "coif15")){
double *coeffTemp;
coeffTemp = malloc(N*sizeof(double));
coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif15, N, coeffTemp);
for (i = 0; i < N; ++i) {
@ -4019,7 +4019,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
}
else if (!strcmp(name, "coif16")){
double *coeffTemp;
coeffTemp = malloc(N*sizeof(double));
coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif16, N, coeffTemp);
for (i = 0; i < N; ++i) {
@ -4036,7 +4036,7 @@ int filtcoef(const char* name, double *lp1, double *hp1, double *lp2, double *hp
}
else if (!strcmp(name, "coif17")){
double *coeffTemp;
coeffTemp = malloc(N*sizeof(double));
coeffTemp = (double*)malloc(N*sizeof(double));
copy(coif17, N, coeffTemp);
for (i = 0; i < N; ++i) {

View File

@ -5,12 +5,25 @@
#include "BoostTest.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <sstream>
#include <string>
#include <cmath>
#include <iostream>
#include "../../src/wavelib.h"
#include<vector>
namespace patch
{
template < typename T > std::string to_string( const T& n )
{
std::ostringstream stm ;
stm << n ;
return stm.str() ;
}
}
double absmax(double *array, int N) {
double max;
int i;
@ -125,15 +138,15 @@ BOOST_AUTO_TEST_CASE(ReconstructionTest)
for (unsigned int j = 0; j < 36; j++)
{
waveletNames.push_back(std::string("db") + std::to_string(j + 1));
waveletNames.push_back(std::string("db") + patch::to_string(j + 1));
}
for (unsigned int j = 0; j < 17; j++)
{
waveletNames.push_back(std::string("coif") + std::to_string(j + 1));
waveletNames.push_back(std::string("coif") + patch::to_string(j + 1));
}
for (unsigned int j = 1; j < 20; j++)
{
waveletNames.push_back(std::string("sym") + std::to_string(j + 1));
waveletNames.push_back(std::string("sym") + patch::to_string(j + 1));
}
waveletNames.push_back("bior1.1");
@ -206,14 +219,18 @@ BOOST_AUTO_TEST_CASE(ReconstructionTest)
wt_free(wt);
}
wave_free(obj);
delete[] name;
}
}
}
fclose(ifp);
free(out);
free(inp);
}
BOOST_AUTO_TEST_CASE(DBCoefTests)
{
wave_object obj;
@ -222,7 +239,7 @@ BOOST_AUTO_TEST_CASE(DBCoefTests)
waveletNames.resize(38);
for (unsigned int i = 0; i < waveletNames.size();i++)
{
waveletNames[i] = std::string("db") + std::to_string(i+1);
waveletNames[i] = std::string("db") + patch::to_string(i+1);
}
for (unsigned int j = 0; j < waveletNames.size(); j++)
@ -237,6 +254,7 @@ BOOST_AUTO_TEST_CASE(DBCoefTests)
for (int m = 1; m < (obj->lpr_len / 2) - 1;m++)
BOOST_CHECK_SMALL(sum5(obj->lpr, obj->lpr_len, m), epsilon);
wave_free(obj);
delete[] name;
}
}
@ -249,7 +267,7 @@ BOOST_AUTO_TEST_CASE(CoifCoefTests)
waveletNames.resize(17);
for (unsigned int i = 0; i < waveletNames.size(); i++)
{
waveletNames[i] = std::string("coif") + std::to_string(i + 1);
waveletNames[i] = std::string("coif") + patch::to_string(i + 1);
}
for (unsigned int j = 0; j < waveletNames.size(); j++)
@ -264,6 +282,7 @@ BOOST_AUTO_TEST_CASE(CoifCoefTests)
for (int m = 1; m < (obj->lpr_len / 2) - 1; m++)
BOOST_CHECK_SMALL(sum5(obj->lpr, obj->lpr_len, m), epsilon);
wave_free(obj);
delete[] name;
}
}
@ -274,7 +293,7 @@ BOOST_AUTO_TEST_CASE(SymCoefTests)
std::vector<std::string > waveletNames;
for (unsigned int i = 1; i < 20; i++)
{
waveletNames.push_back(std::string("sym") + std::to_string(i + 1));
waveletNames.push_back(std::string("sym") + patch::to_string(i + 1));
}
for (unsigned int j = 0; j < waveletNames.size(); j++)
@ -289,6 +308,7 @@ BOOST_AUTO_TEST_CASE(SymCoefTests)
for (int m = 1; m < (obj->lpr_len / 2) - 1; m++)
BOOST_CHECK_SMALL(sum5(obj->lpr, obj->lpr_len, m), epsilon);
wave_free(obj);
delete[] name;
}
}
@ -326,9 +346,10 @@ BOOST_AUTO_TEST_CASE(BiorCoefTests)
BOOST_CHECK_SMALL(sum3(obj->lpr, obj->lpr_len) - 1. / std::sqrt(2.0), epsilon);
BOOST_CHECK_SMALL(sum3(obj->lpd, obj->lpd_len) - 1. / std::sqrt(2.0), epsilon);
wave_free(obj);
delete[] name;
}
}
*/
BOOST_AUTO_TEST_CASE(RBiorCoefTests)
{
wave_object obj;
@ -363,6 +384,7 @@ BOOST_AUTO_TEST_CASE(RBiorCoefTests)
BOOST_CHECK_SMALL(sum3(obj->lpr, obj->lpr_len) - 1. / std::sqrt(2.0), epsilon);
BOOST_CHECK_SMALL(sum3(obj->lpd, obj->lpd_len) - 1. / std::sqrt(2.0), epsilon);
wave_free(obj);
delete[] name;
}
}