Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove memory leak in vector.c #1302

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions data_structures/vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void init(Vector* vec, int val) {
* @returns: none
*/
void delete(Vector* vec) {
free(vec->contents);
free(vec->contents);
}

/**
Expand All @@ -54,7 +54,7 @@ void clear(Vector* vec) {
* @returns: int
*/
int len(Vector* vec) {
return vec->len;
return vec->len;
}

/**
Expand Down Expand Up @@ -118,7 +118,7 @@ void* begin(Vector* vec) {
}

/**
* This function prints the entire Vector as a list.
* This function prints the entire Vector as a list.
* @params Vector* (a pointer to the Vector struct)
* @returns: none
*/
Expand Down Expand Up @@ -147,6 +147,7 @@ static void test() {
set(&vec, 1, 22);
assert(get(&vec, 1) == 22);
assert(len(&vec) == 2);
delete(&vec);
vil02 marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand All @@ -164,5 +165,6 @@ int main() {
set(&vec, 1, 22);
print(&vec);
printf("Length: %d\n", len(&vec));
delete(&vec);
vil02 marked this conversation as resolved.
Show resolved Hide resolved
return 0;
}
Loading