Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Free Nothing

Free Nothing

Scheduled Pinned Locked Moved The Weird and The Wonderful
14 Posts 10 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Jim Warburton

    Previously in the code both flag and fval were malloc'd

    flag = NULL;
    free(flag);

    fval = NULL;
    free(fval);

    this thing looks like it was written by an epileptic ferret Dave Kreskowiak

    P Offline
    P Offline
    PIEBALDconsult
    wrote on last edited by
    #2

    What is NULL #defined as? :-D

    1 Reply Last reply
    0
    • J Jim Warburton

      Previously in the code both flag and fval were malloc'd

      flag = NULL;
      free(flag);

      fval = NULL;
      free(fval);

      this thing looks like it was written by an epileptic ferret Dave Kreskowiak

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #3

      What's the problem? 1. Remove all references 2. Invoke the GC ;P

      xacc.ide - now with TabsToSpaces support
      IronScheme - 1.0 alpha 3 out now

      P 1 Reply Last reply
      0
      • L leppie

        What's the problem? 1. Remove all references 2. Invoke the GC ;P

        xacc.ide - now with TabsToSpaces support
        IronScheme - 1.0 alpha 3 out now

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #4

        Aaaah, yeah... NULL could be a collection of references to be freed. :-D

        J 1 Reply Last reply
        0
        • P PIEBALDconsult

          Aaaah, yeah... NULL could be a collection of references to be freed. :-D

          J Offline
          J Offline
          jamie550
          wrote on last edited by
          #5

          But wouldn't that free NULL twice?

          V 1 Reply Last reply
          0
          • J Jim Warburton

            Previously in the code both flag and fval were malloc'd

            flag = NULL;
            free(flag);

            fval = NULL;
            free(fval);

            this thing looks like it was written by an epileptic ferret Dave Kreskowiak

            S Offline
            S Offline
            Sharjith
            wrote on last edited by
            #6

            flag = NULL sets it to point to nothing. This makes the memory location lost. flag = (data_type*)malloc(sizeof(data_type)); This returns address of the memory allocated by malloc and assignes the address value to flag - something like flag = 0x2345cf. This is a valid address it is pointing to. When you say flag = NULL, flag points to nothing, then you cannot free flag because you cannot free something that does not exist. So first free(flag); then set flag = NULL; i.e. just change the sequence to- free(flag); flag = NULL; free(fval); fval = NULL; :)

            C 1 Reply Last reply
            0
            • J Jim Warburton

              Previously in the code both flag and fval were malloc'd

              flag = NULL;
              free(flag);

              fval = NULL;
              free(fval);

              this thing looks like it was written by an epileptic ferret Dave Kreskowiak

              V Offline
              V Offline
              Vasudevan Deepak Kumar
              wrote on last edited by
              #7

              :-D

              Vasudevan Deepak Kumar Personal Homepage
              Tech Gossips
              A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson

              1 Reply Last reply
              0
              • J jamie550

                But wouldn't that free NULL twice?

                V Offline
                V Offline
                Vasudevan Deepak Kumar
                wrote on last edited by
                #8

                In an effort to gain more memory by showing negative used space!

                Vasudevan Deepak Kumar Personal Homepage
                Tech Gossips
                A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson

                1 Reply Last reply
                0
                • S Sharjith

                  flag = NULL sets it to point to nothing. This makes the memory location lost. flag = (data_type*)malloc(sizeof(data_type)); This returns address of the memory allocated by malloc and assignes the address value to flag - something like flag = 0x2345cf. This is a valid address it is pointing to. When you say flag = NULL, flag points to nothing, then you cannot free flag because you cannot free something that does not exist. So first free(flag); then set flag = NULL; i.e. just change the sequence to- free(flag); flag = NULL; free(fval); fval = NULL; :)

                  C Offline
                  C Offline
                  Cedric Moonen
                  wrote on last edited by
                  #9

                  :laugh: You didn't take your coffee this morning ? Did you forget to read the title of the forum ?

                  Cédric Moonen Software developer
                  Charting control [v1.4]

                  L 1 Reply Last reply
                  0
                  • C Cedric Moonen

                    :laugh: You didn't take your coffee this morning ? Did you forget to read the title of the forum ?

                    Cédric Moonen Software developer
                    Charting control [v1.4]

                    L Offline
                    L Offline
                    leppie
                    wrote on last edited by
                    #10

                    I wasn't so sure if I should tell him that ;P

                    xacc.ide - now with TabsToSpaces support
                    IronScheme - 1.0 alpha 3 out now

                    1 Reply Last reply
                    0
                    • J Jim Warburton

                      Previously in the code both flag and fval were malloc'd

                      flag = NULL;
                      free(flag);

                      fval = NULL;
                      free(fval);

                      this thing looks like it was written by an epileptic ferret Dave Kreskowiak

                      E Offline
                      E Offline
                      etkid84
                      wrote on last edited by
                      #11

                      reminds me of the NRA and gun advocacy... it's the shooter not the gun it's the programmer not the language

                      David

                      D P 2 Replies Last reply
                      0
                      • E etkid84

                        reminds me of the NRA and gun advocacy... it's the shooter not the gun it's the programmer not the language

                        David

                        D Offline
                        D Offline
                        Dan Neely
                        wrote on last edited by
                        #12

                        "Ray guns don't vaporize Zorbonians. Zorbonians vaporize Zorbonians." Gary Larson

                        You know, every time I tried to win a bar-bet about being able to count to 1000 using my fingers I always got punched out when I reached 4.... -- El Corazon

                        1 Reply Last reply
                        0
                        • E etkid84

                          reminds me of the NRA and gun advocacy... it's the shooter not the gun it's the programmer not the language

                          David

                          P Offline
                          P Offline
                          PIEBALDconsult
                          wrote on last edited by
                          #13

                          Oh, great, now I have an opening for something I was thinking yesterday: A song that was playing used the phrase, "the wrong end of a gun". Does the anti-gun crew consider both ends of a gun to be "wrong"? :confused:

                          1 Reply Last reply
                          0
                          • J Jim Warburton

                            Previously in the code both flag and fval were malloc'd

                            flag = NULL;
                            free(flag);

                            fval = NULL;
                            free(fval);

                            this thing looks like it was written by an epileptic ferret Dave Kreskowiak

                            S Offline
                            S Offline
                            supercat9
                            wrote on last edited by
                            #14

                            Too bad 'free()' wasn't defined as returning a (void *). In that case, the code could have been written as: flag = free(flag); In case of any error other than a null pointer being passed in, free() could return the passed-in pointer. Similar behavior could have been used with fclose() [return a (FILE*)] and other such functions that destroy the object whose pointer is passed to them. Oh well, only a few decades too late now.... Where's my time machine?

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups