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 6784157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:57:21+00:00 2026-05-26T16:57:21+00:00

I have a inline function defined as following: inline string Change(char *pointer) { string

  • 0

I have a inline function defined as following:

inline string Change(char *pointer) {
    string str;
    char temp[32] = "";

    sprintf(temp,"%c:%c:%c:%c:%c:%c", //line 1
        temp[0],temp[1],temp[2],
        temp[3],temp[4],temp[5],
    );

    str = temp;
    return str;
}

when I use memory leak tool to check it, it indicates line 1(marked above) is memory leak.
What is the problem of the above code?

  • 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. Editorial Team
    Editorial Team
    2026-05-26T16:57:22+00:00Added an answer on May 26, 2026 at 4:57 pm

    I created fully compilable example:

    #include <string>
    #include <iostream>
    #include <cstdio>
    
    std::string Change( char * ) {
        std::string str;
        char temp[32] = "";
    
        sprintf(temp,"%c:%c:%c:%c:%c:%c", //line 1
            temp[0],temp[1],temp[2],
            temp[3],temp[4],temp[5]
        );
    
        str = temp;
        return str;
    }
    
    int main()
    {
        char a[]={"abaaaaa2"};
        std::cout<<Change(a)<<std::endl;
    }
    

    When running under valgrind, I get no leaks detected:

    ==16829== 
    ==16829== HEAP SUMMARY:
    ==16829==     in use at exit: 0 bytes in 0 blocks
    ==16829==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
    ==16829== 
    ==16829== All heap blocks were freed -- no leaks are possible
    ==16829== 
    ==16829== For counts of detected and suppressed errors, rerun with: -v
    ==16829== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 15 from 8)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an inline member function defined under class MyClass int MyClass::myInlineFunction(); This function
The linker is reporting multiply defined errors for an inline function. I have the
I recently answered this question how-to-call-user-defined-function-in-order-to-use-with-select-group-by-order-by My answer was to use an inline view
Assume I have a function template like this: template<class T> inline void doStuff(T* arr)
The following practice is fairly commonplace in the inline JavaScript I have to work
I have the following code, which uses the eval function: lines = self.fulltext.splitlines() CURRENT
I have developed a cumulative sum function as defined below in the Haskell library
I have a conflict when I use a jquery script for inline window and
I am getting the warning: function used but not defined . I have static
I have a hash function defined in a header file which I want to

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.