Thread: malloc HELP

  1. #1
    Registered User
    Join Date
    Oct 2019
    Posts
    1

    malloc HELP

    I need help with the syntax for the malloc function, I'm trying to write this code and everything seems to be working fine apart from one warning message. So I've written:
    double *a;
    double *b;
    a = (double*)malloc(s);
    b = (double*)malloc(s);
    ~~
    code
    ~~
    free(&a);
    free(&b);
    s is the number of points. It keeps saying "attempt to free a non heap object". Does anyone know what might be going wrong here?

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,452
    A couple of things, first in C you shouldn't be casting the return value from malloc(), second what is "s"? Third did you look up some documentation for free, pay particular attention to what you're passing to that function, and remember that "a" and "b" are already pointers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 05-19-2010, 02:12 AM
  2. Replies: 7
    Last Post: 10-01-2008, 07:45 PM
  3. malloc() under DOS
    By knutso in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-18-2003, 07:06 AM
  4. malloc
    By powerboy in forum C Programming
    Replies: 11
    Last Post: 05-25-2003, 09:26 AM
  5. New vs Malloc again!
    By Bajanine in forum Windows Programming
    Replies: 3
    Last Post: 05-13-2003, 09:56 PM

Tags for this Thread