analyze each program and figure out what is wrong with the memory management in the code and how to fix the code. #include <unistd.h>#include <stdio.h>#include <stdlib.h>#include <assert.h> voidmyfunction(int size) {int *p;p = malloc(size*sizeof(int));assert(p != NULL);for (int i = 0; i < size; i++) {p[i] = 1;}} intmain(int argc, char *argv[]){if (argc != 2) { fprintf(stderr, "usage: broken5 <value>\n"); exit(1); } int size = atoi(argv[1]);int counter = 0;while(1) { // the infinite while loop is NOT a bugmyfunction(size);printf("%d \t", counter);counter++;} return 0;}


analyze each program and figure out what is wrong with the memory management in the code and how to fix the code.

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

myfunction(int size) {
int *p;
p = malloc(size*sizeof(int));
assert(p != NULL);
for (int i = 0; i < size; i++) {
p[i] = 1;

main(int argc, char *argv[])
if (argc != 2) {
fprintf(stderr, "usage: broken5 <value>\n");
int size = atoi(argv[1]);
int counter = 0;
while(1) { // the infinite while loop is NOT a bug
printf("%d \t", counter);

return 0;

Expert Answer

Want to see the step-by-step answer?

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.
Tagged in
Computer Science

Programing Language

Related Computer Science Q&A

Find answers to questions asked by students like you.

Q: Why am I getting a error message when trying to INSERT data for the table??   (photo attached)

A: The syntax to insert data in the table isINSERT INTO Table_Name (field_Name1, field_Name2, field_Nam...

Q: Which of the following is used to communicate with the network? Southbound API Northbound API Northb...

A: To communicate with the network, better Application program Interface is: Northbound API is supposed...

Q: Using the code in part I of this lab (included below): 1. Create a function to INPUT the information...

A:  Create a function INPUT which takes a structure variable as parameter.Pass structure variable using...

Q: Let s1 be " Welcome " and s2 be " welcome ". Write the code for the following statements:a. Check wh...

A: We’ll answer the first three subparts of the question since the exact one wasn’t specified. Please s...

Q: Given a nested list named table, use a loop to print each sub list of the nested list. The sub lists...

A: Program descriptionOne 3 x3 list is created to demonstrate the conceptdisplay the elements of the su...

Q: Given the follwing business rules, create an ERD.  The ERD must include all primary keys, foreign ke...

A: ER diagram:

Q: What are the SQL query commands to create the tables (attached) with appropriate attributes and data...

A: Primary key:A primary key is a minimum set of attributes (columns) in a table with uniquely defined ...

Q: How do I write a line of code in Java to find how many numbers are below and above average ?

A: ⦁ Create two variables in the main method and initialize them with zero.⦁ Iterate the all numbers wi...

Q: 13.10 Explain the concept of a DHCP lease. How is it obtained? How is it used? What does it provide?

A: Obtaining DSCP (Dynamic Host Configuration Protocol) lease time:Lease time assigning process depends...