help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Memory Leak??


From: nandakiran
Subject: Memory Leak??
Date: Fri, 24 Aug 2007 12:21:43 -0700
User-agent: G2/1.0

I am using Mandriva Linux (2.6.17-14) with gnu g++ version 4.1.2. The
source code used to test is given below.
When i am run the program, it is properly freeing up the allocated
memory. When also including the
lines that are commented in the code, the "delete" is not freeing up
the memory used. I do not have
the problem when compiling under cygwin.  What can be done to fix
this?

Source Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
        struct node {
                char *value;
                char temp[5000];
                node *right;
        } *head;

int main() {
        int i;
        node* tmp;
        tmp=NULL;
        for (i=0;i<10000;i++) {
                head=new node;
                // head->value = NULL;
                // head->value = new char;
                // *(head->value)='C';
                head->right=tmp;
                tmp=head;
        }
        do {
                tmp=head->right;
                // delete (head->value);
                // head->value=NULL;
                delete head;
                head=tmp;
        } while (head!=NULL);
        printf("OK!\n");
        for (;;);
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]