Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

malloc not returning anything

malloc not returning anything

malloc not returning anything


I am having an issue where allocating memory is not returning focus to my code. the call to malloc is made and the processor is running the program at 100%, but my program makes no further progress. is this an infinite loop inside the malloc code?

I currently have the code:

printf("about to allocate %d bytes\n", length);
song[quality] = malloc(length);
printf("malloc completed\n");

when executed this code gets executed a few times inside a loop and things go acording to plan untill i get the output "about to allocate 16 bytes" and then nothing further happens.

I doubt my application has run out of memory as it happens early in the program when not much has been allocated yet, and even then malloc should return an error message. I have also turned off the "enable over commit memory" feature on my computer as i thought maybe that could be the cause.

has anyone seen something simillar before? Thanks,

RE: malloc not returning anything

Malloc returns a pointer and your assigning it
to a element of an array.
 Your compiler does not
give an error?
 Here's an example

 Don't forget to use FREE or you may allocate all
your memory.

RE: malloc not returning anything

Thanks for the response
song is a 2 dimensional array. so song is an array of pointers (or an array of arrays if you prefer to think of it like that).

for example try compiling the following:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
        char* example[5];
        example[0] = malloc(12);
        strcpy(example[0], "hello world\0");

as an update, i have buggered up my memory somewhere as it produces memory errors for a certain input. Hopefully if i track down and debug that this one will simply go away... (fingers crossed)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close