DAMAGE: after Normal block (#42) at 0x00430160

Hi all, i am trying to traverse through a folder and print its contents, but however getting rudely crashed, has it got anything to do with the queue i have tried to implement ?? Thanx in advance :D
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <stdio.h>
#include <windows.h>
#include <string.h>
#include <stdlib.h>


class queue{
	private:
		struct item{
			char src[255] ;
			struct item *next ;
		} ;
		typedef struct item ITEM ;

		ITEM* head_ptr ;
		ITEM* tail_ptr ;
	
	public:
		queue() ;
		~queue() ;
		int empty() ;
		void front(char *src) ;
		void pop() ;
		void push(char *src) ;
		
} ;

queue::queue()
{
	head_ptr = NULL ;
	tail_ptr = NULL ;
}

void queue::push(char *src)
{
	ITEM* temp = (ITEM*)malloc(sizeof(temp)) ;
	strcpy(temp->src, src) ;
	temp->next = NULL ;

	if (head_ptr == NULL){
		head_ptr = temp ;
		//tail_ptr = temp ;
	}else{
		tail_ptr->next = temp ;
		
	}
	tail_ptr = temp ;
	
}

void queue::pop()
{
	ITEM* temp = NULL ;
	temp = head_ptr ;
	head_ptr = head_ptr->next ;
	if (head_ptr == NULL){
		tail_ptr = NULL ;
	}else{
		head_ptr = head_ptr->next ;
	}
	free(temp) ;
}

int queue::empty()
{
	return (head_ptr == NULL) ;
}

void queue::front(char *src)
{
	if (head_ptr) strcpy(src, head_ptr->src) ;
}

queue::~queue()
{
	ITEM* temp = NULL ;
	while (head_ptr->next){
		temp = head_ptr ;
		head_ptr = head_ptr->next ;
		free(temp) ;
	}
	free(head_ptr) ;
	head_ptr = NULL ;
	tail_ptr = NULL ;
}

struct OPERATIONDESC{
	char src[255] ;
	char dest[255] ;
} ;

void folder_traverse(void *id)
{
	char level[255] ;
	char temp[255] ;
	char temp_1[255] ;

	HANDLE h ;
	WIN32_FIND_DATA info ;

	struct OPERATIONDESC* op = (struct OPERATIONDESC*)id ;
	queue q ;
	
	q.push(op->src) ;

	while (!q.empty()){
		q.front(level) ;
		q.pop() ;
		
		strcpy(temp, level) ;
		strcat(temp, "\\*.*") ;

		h = FindFirstFile(temp, &info) ;
		do{
			if (!strcmp(info.cFileName, ".")) continue ;
			if (!strcmp(info.cFileName, "..")) continue ;
			
			strcpy(temp_1, level) ;
			strcat(temp_1, "\\") ;
			strcat(temp_1, info.cFileName) ;

			if(info.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY){
				q.push(temp_1) ;
			}else{
				printf("%s\n", temp_1) ;
			}
		}while (FindNextFile(h, &info)) ;



	}

}
int main()
{
	struct OPERATIONDESC d ;
	strcpy(d.src, "c:\\test") ;
	folder_traverse((void*)&d) ;
	return 0 ;


}
1
2
3
4
5
6
7
void queue::push(char *src)
{
	ITEM* temp = (ITEM*)malloc(sizeof(temp)) ;//<<==/ERROR here - 
	strcpy(temp->src, src) ;
	temp->next = NULL ;

        ....
Last edited on
Thanx :D. I have changed that and still getting crashed. What could it be, running the debugger i see it is crashing after popping twice. ther's got to b a catch smwhere. hoping ur response. :D
OK I assume that you changed it to this:
ITEM* temp = (ITEM*)malloc(sizeof(ITEM)) ;


This bit doesn't look right to me:
1
2
3
4
5
6
7
8
9
10
11
12
void queue::pop()
{
	ITEM* temp = NULL ;
	temp = head_ptr ;
	head_ptr = head_ptr->next ;
	if (head_ptr == NULL){
		tail_ptr = NULL ;
	}else{
		head_ptr = head_ptr->next ;//<<===== ?????
	}
	free(temp) ;
}


I believe it is causing a problem later on with the destructor because head_ptr is NULL
1
2
3
4
5
6
7
8
9
10
11
12
queue::~queue()
{
	ITEM* temp = NULL ;
	while (head_ptr->next){
		temp = head_ptr ;
		head_ptr = head_ptr->next ;
		free(temp) ;
	}
	free(head_ptr) ; 
	head_ptr = NULL ;
	tail_ptr = NULL ;
}
Oh thank you very much. Actually i have been skipping my data structure classes a lot (thought there's always STL). But now at the end of the year suffering a lot as teachers won't allow STL in the projects. :D. Thanx again you have been very helpful indeed.
Topic archived. No new replies allowed.