Ask about free funtion using with malloc

This is a discussion on Ask about free funtion using with malloc within the C++ Programming forums, part of the General Programming Boards category; I show some part of my code below (there are malloc funtions in this part) At first time I use ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    68

    Talking Ask about free funtion using with malloc

    I show some part of my code below (there are malloc funtions in this part)
    At first time I use malloc function but not use free function and I debug my program and see value of c,d and o in debug window .They are correct. After that there are error message about dbgheap.c and sbheap.c I think this error cuase by malloc function.So I want to ask you about where can I use free function at this code

    int i;
    int k;
    int l;
    int m;
    int n;
    int len;
    unsigned char *c;
    unsigned char *d;
    unsigned char *o;
    int h = 0;
    c = malloc(len*sizeof(unsigned char));
    d = malloc(2*len*sizeof(unsigned char));
    o = malloc(2*len*sizeof(unsigned char));
    for(i=2;i<len-4;i+=5) {
    /* Convert from base 900 to base 256 */
    int j;
    unsigned char b[6];
    UInt64 codeval = 0;

    if (i==len-5 && type!=924) break;
    for(j=0;j<5;++j) {
    codeval *= 900;
    codeval += codewords[i+j];
    }
    for(j=0;j<6;++j) {
    b[5-j] = codeval%256;
    codeval >>= 8;
    }

    for(l=0;l<6;++l) {
    c[h] = b[l];
    ++h;
    k = h;
    }
    }
    for(;i<len;++i) {
    unsigned char b = codewords[i];
    c[h] = b;
    ++h;
    k = h;
    }
    m = 0;

    for (h=0;h<k;++h){
    n = c[h];
    d[m] = n/16;
    if ((d[m] >= 0)&&(d[m] < 10))
    {
    o[m] = d[m] + 48;
    }
    else if ((d[m] > 9) && (d[m] < 17))
    {
    o[m] = d[m] + 55;
    }

    d[m+1] = n%16;
    if ((d[m+1] >= 0)&&(d[m+1] < 10))
    {
    o[m+1] = d[m+1] + 48;
    }
    else if ((d[m+1] > 9) && (d[m+1] < 17))
    {
    o[m+1] = d[m+1] + 55;
    }
    m = m+2;
    }

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    I vote that mods should DELETE any posts IMMEDIATLY that dont have CODE tags, anyone else with me?
    "There are three kinds of people in the world...
    Those that can count and those that can't."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory leaks problem in C -- Help please
    By Amely in forum C Programming
    Replies: 14
    Last Post: 05-21-2008, 12:16 PM
  2. OS out of memory if malloc without free?
    By hkuser2001 in forum C Programming
    Replies: 7
    Last Post: 04-24-2006, 08:23 AM
  3. Function to check memory left from malloc and free?
    By Lechx in forum C Programming
    Replies: 4
    Last Post: 04-24-2006, 06:45 AM
  4. String malloc & free?
    By The Tracker in forum C Programming
    Replies: 2
    Last Post: 05-22-2002, 11:45 PM
  5. Malloc and Free.....
    By heljy in forum C Programming
    Replies: 5
    Last Post: 04-14-2002, 10:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21