Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 58259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:49:12+00:00 2026-05-10T17:49:12+00:00

I am using Borland Builder C++. I have a memory leak and I know

  • 0

I am using Borland Builder C++. I have a memory leak and I know it must be because of this class I created, but I am not sure how to fix it. Please look at my code– any ideas would be greatly appreciated!

Here’s the .h file:

#ifndef HeaderH #define HeaderH #include <vcl.h> #include <string> using std::string; class Header {   public:     //File Header     char FileTitle[31];     char OriginatorName[16];      //Image Header     char ImageDateTime[15];     char ImageCordsRep[2];     char ImageGeoLocation[61];      NitfHeader(double latitude, double longitude, double altitude, double heading);     ~NitfHeader();     void SetHeader(char * date, char * time, double location[4][2]);      private:      void ConvertToDegMinSec (double angle, AnsiString & s, bool IsLongitude);     AnsiString ImageDate;     AnsiString ImageTime;     AnsiString Latitude_d;     AnsiString Longitude_d;     double Latitude;     double Longitude;     double Heading;     double Altitude;  }; 

And here is some of the .cpp file:

void Header::SetHeader(char * date, char * time, double location[4][2]){     //File Header strcpy(FileTitle,'Cannon Powershot A640'); strcpy(OperatorName,'Camera Operator');     //Image Header //Image Date and Time    ImageDate = AnsiString(date);    ImageTime = AnsiString(time);    AnsiString secstr = AnsiString(ImageTime.SubString(7,2));    AnsiString rounder = AnsiString(ImageDate.SubString(10,1));    int seconds = secstr.ToInt();     //Round off seconds  - will this be necessary with format hh:mm:ss in text file?    if (rounder.ToInt() > 4) {      seconds++;     }    AnsiString dateTime = ImageDate.SubString(7,4)+ ImageDate.SubString(4,2) + ImageDate.SubString(1,2) + ImageTime.SubString(1,2)                     + ImageTime.SubString(4,2) + AnsiString(seconds);    strcpy(ImageDateTime,dateTime.c_str());     //Image Coordinates Representation    strcpy(ImageCordsRep,'G');     //Image Geographic Location    AnsiString lat;    AnsiString lon;    AnsiString locationlat_d;    AnsiString locationlon_d;    AnsiString corner;     for (int i = 0; i < 4; i++){       ConvertToDegMinSec(location[i][0],lat,false);      ConvertToDegMinSec(location[i][1],lon,true);       if(location[i][0] < 0){         locationlat_d = 'S';         ConvertToDegMinSec(-location[i][0],lat,false);       }else if(location[i][0] > 0){         locationlat_d = 'N';      }else locationlat_d = ' ';       if(location[i][1] < 0){         locationlon_d = 'W';         ConvertToDegMinSec(-location[i][1],lon,true);      }else if(location[i][1] > 0){          locationlon_d = 'E';      }else locationlon_d = ' ';       corner += lat + locationlat_d + lon + locationlon_d;     }    strcpy(ImageGeoLocation,corner.c_str());  }   

Now when I use the class in main, basically I just create a pointer:

Header * header = new Header; header->SetHeader(t[5],t[6],corners->location); char * imageLocation = header->ImageGeoLocation; //do something with imageLocation delete header; 

Where corners->location is a string from another class, and t[5] and t[6] are both strings. The problem is that imageLocation doesn’t contain what is expected, and often just garbage. I have read a lot about memory leaks and pointers, but I am still very new to programming and some of it is quite confusing. Any suggestions would be fabulous!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T17:49:12+00:00Added an answer on May 10, 2026 at 5:49 pm

    I’m afraid there are a number of issues here.

    For starters char ImageCordsRep[1]; doesn’t work … a string is always null terminated, so when you do strcpy(ImageCordsRep,'G'); you are overflowing the buffer.

    It would also be good practice to terminate all those string buffers with a null in your constructor, so they are always valid strings.

    Even better would be to use a string class instead of the char arrays, or at least use ‘strncpy’ to prevent buffer overruns if the incoming strings are larger than you expect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 197k
  • Answers 197k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I doubt there's a better way than listing out the… May 12, 2026 at 7:20 pm
  • Editorial Team
    Editorial Team added an answer In a dynamically-typed language, the identification and optimization of a… May 12, 2026 at 7:20 pm
  • Editorial Team
    Editorial Team added an answer Android supports OpenGL ES 1.0 which overlaps with OpenGL 1.3… May 12, 2026 at 7:20 pm

Related Questions

I am using VS2008 to develop a WinForms 2.0 application. I have read about
I am using Borland Builder C++ 2009. I want to add a button to
I am using borland 2006 c++, and have following code. I am using vectors,
To preface I am using Borland C++ and the VCL. I need some sort

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.