Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help from question 1 through 5. Question 1-4 only has 1 answer allowed for each and question 5 can have multiple. Memory leak detection

image text in transcribed

Need help from question 1 through 5. Question 1-4 only has 1 answer allowed for each and question 5 can have multiple.

Memory leak detection exercise Program A Program B struct actor { 1. Which piece of code struct actor { 4. Where should the actor char name[32]; has memory leak? char *name; object linked to c be a) struct actor *next; Neither A nor B freed? struct actor *next; b) Both A and B } *head = NULL; a) In get_name() in A } *head = NULL; c) A b) In insertion() in A char *get_name() d) B char *get_name() c) In main() function { char *q; d) In deletion() function 2. Which piece of { char *q; q = (char *) malloc(32); memory is leaked? q = (char *) malloc(32); printf("Please enter a name: "); a) malloc(32) in A printf("Please enter a name: "); scanf("%s", q); return q; b) malloc(32) in B scanf("%s", q); return q; c) char name[32] in A }; d) char name[32] in B int insertion() int insertion() { actor *c; char *n; { actor *c; char *n; c = malloc(sizeof(struct actor)); c = malloc(sizeof(struct actor)); if (c == 0) { if (c == 0) { printf("out of memory "); return -1;} printf("out of memory "); return -1;} n = get_name(); C->name = get_name(); 3. Where should the strcpy(c->name, n); free(n); C->next = head; memory be freed? 5. When you write the head = c; C->next = head; a) In get_name() in A deletion function for A&B, head = c; b) In get name() in B return 1 how many free() calls are return 1 c) In insertion() in A }; required? Select all that apply. d) In insertion() in B }; [ ] One for Program A [ ] Two for Program A CSE240 Please take online test after the lecture! [ ] One for Program B 0/23/2017 [ ] Two for Program B

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago