title: C Memory leak issue
body: <p>Program is leaking memory and not able to fix it... This Program is reading data from text files and after reading data, it perform certain operation on data during this it leaks memory. Device has very limited memory &amp; flash drive due to this I cannot run memory leaks checking tools. 
  Please advise to fix the memory leak issue
  Please find code snippet below</p>
  
  <pre><code>int LanguageRequiredData(void)
  {
  
     char *data=NULL;
     int retValue = 0 ;
  
     retValue = GetString_English(&amp;data);
     if(retValue&gt;0 &amp;&amp; strlen(data)&gt;0)
     {
        // Do Some Operation
     }
  
     if (data!=NULL)
    {
        Mem_free(data);
        data = NULL;
    }
  }
  
  
  int GetString_English(char **data)
  {
  
      int retValue = 0 ;
  
      retValue = File_LoadContent(LANGSENGFILE,&amp;(*data));
  
      return retValue;
  }
  
  
  int File_LoadContent (char *file, char **content) 
  {
  
     long size = File_Size(file); 
     char buf[256]={};
  
     memset(buf,0x00,sizeof(buf));
     if (*content)
    {
      Mem_free(*content);
    }
    *content = (char*) Mem_alloc((size+1) * sizeof(char));
  
    TFILE * fd; fd=File_Open(file,"r"); if (fd==NULL) return 0;
    while (File_Gets(buf,sizeof(buf),fd)!=NULL)
    {
      strcat(*content,buf);
      memset(buf,0x00,sizeof(buf));
    }
    File_Close(fd); return 1;
  }
  
  
  void * Mem_alloc(size_t size)
  {
     int    i;
     void * ptr = NULL;
  
     for (i = 0; i &lt; 2; i++)
     {
        ptr = malloc(size);
  
        if (ptr)
        {
           break;
        }
     }
  
    if (ptr)
    {
        memset(ptr, 0, size);
     }
  
    return ptr;
  }
  
  void Mem_free(void * ptr)
  {    
     if (ptr != NULL)
    { 
       free(ptr);
    }
  
    ptr = NULL;    
  }
  </code></pre>