Error message: malloc: error for Object 0x7: Pointer being Freed was not allocated

Asked

Viewed 107 times

0

My program is giving this error message:

malloc: * error for Object 0x7: Pointer being Freed was not allocated * set a breakpoint in malloc_error_break to debug

Would anyone know why?

The code is this:

DIR *dir;
struct dirent *entrada;
unsigned char isFile = 0x8;

struct tipo_seq {
    int tarefa;
    int valor;
};

struct tipo_multi {
    int adiantamento;
    int atraso;
    int total;
};

//variáveis globais
int numtar, nummaq;
int pjk[NMAX+1][MMAX+1], sjk[NMAX+1][MMAX+1], Cjk[NMAX+1][MMAX+1], dj[NMAX+1];
tipo_seq *sequencia = new tipo_seq;

//programa principal
int main()
{
    int j, k;
    string aux, diretorio;

    ifstream arquivo; //define variável tipo arquivo
    //ofstream saida;

    if ((dir =  opendir("/Users/heliofuchigami/Documents/FSJIT/benchmark/testes/")) != NULL){
        //lista todos os arquivos do diretório
        while ((entrada = readdir (dir)) != NULL){
            if (entrada->d_type == isFile){
                cout << entrada->d_name << endl;

                diretorio = "/Users/heliofuchigami/Documents/FSJIT/benchmark/testes/";
                diretorio += entrada->d_name;

                arquivo.open(diretorio, ios::in);

                //leitura dos dados do arquivo
                arquivo >> numtar;
                arquivo >> nummaq;

                for (j=1; j<=numtar; j++)
                    for (k=1; k<=nummaq; k++)
                        arquivo >> pjk[j][k];

                arquivo >> aux; //lê "SI"

                for (j=1; j<=numtar; j++)
                    for (k=1; k<=nummaq; k++)
                        arquivo >> sjk[j][k];

                arquivo >> aux; //lê "DUEDATE"

                for (j=1; j<=numtar; j++)
                    arquivo >> dj[j];

                arquivo.close();

                //inicializa variáveis
                for (j=0; j<=numtar; j++)
                    for (k=0; k<=nummaq; k++)
                        Cjk[j][k] = 0;

                //resolve o problema
                AlgoritmoColoniadeFormigas();

            }
        }

        closedir(dir);

    } else return EXIT_FAILURE;


    getchar();

    //libera memória das alocações dinâmicas
    delete [] sequencia;

    return 0;

}
  • Use a debugger to find out which error line is and put here, please.

  • Hard to be sure without access to full code but taking a quick look at to see that there is at least one memory error since you do tipo_seq *sequencia = new tipo_seq; and then release using delete[] which should only be used when allocating an object array.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.