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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:52:02+00:00 2026-05-27T02:52:02+00:00

I came across an issue that I am not sure if it’s an issue

  • 0

I came across an issue that I am not sure if it’s an issue at all. I have a simple C funcion that gets a char* passed from string like so:



 #include <stdio.h>
 #include <stdlib.h>

int main(int argc, char** argv) {

    passString("hello");

    return (EXIT_SUCCESS);
}

void passString(char * string) {
    // .... some code ....
    free(string); // ???
}

and I was taught to free every memory block that I’m not working with anymore (mainly arrays). So my though was to free string as well but the program freezes or crashes even with this simple example. I’m not sure whether I really need to free string here or not and if so how do I achieve that?

  • 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-27T02:52:03+00:00Added an answer on May 27, 2026 at 2:52 am

    You do not need to free memory which you did not allocate with malloc.

    In your example string is not allocated by malloc in your program so you do not need to free it. string is a string literal and is allocated somewhere in the read-only memory(implementation defined) and is automatically freed.

    For standerdese fans:

    References:
    c99 Standard: 7.20.3.2 The free function

    Synopsis
    #include
    void free(void *ptr);

    Description:
    The free function causes the space pointed to by ptr to be deallocated, that is, made
    available for further allocation. If ptr is a null pointer, no action occurs. Otherwise, if
    the argument does not match a pointer earlier returned by the calloc, malloc,or
    realloc function, or if the space has been deallocated by a call to free or realloc,
    the behavior is undefined
    .

    Returns
    The free function returns no value.

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

Sidebar

Related Questions

Just came across an issue with my Wordpress template that I can't figure out.
I came across this issue last night where my CSS would not affect the
While familiarizing myself with AJAX, I came across the following issue I do not
While testing a new application, we came across an issue that sometimes a stored
I'm new to grails and came across an issue of grails shell not recompiling
Recently we came across an issue to support side by side installation. We have
An interesting issue came up recently. We came across some code that is using
i came across a compatibility issue today, as a customer upgraded from Windows XP
I came across a strange issue in Python when using global variables. I have
I came across an issue where, just to try it out, I removed an

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.