Question: 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

 Need help from question 1 through 5. Question 1-4 only has

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!