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. General Programming
  3. C / C++ / MFC
  4. Memory leak when return char* from DLL

Memory leak when return char* from DLL

Scheduled Pinned Locked Moved C / C++ / MFC
22 Posts 7 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.
  • N Niklas L

    shivanandgupta wrote:

    if we use cData='\0' and after this "delete []cData;" then memory leak still continue.

    Well, if you set cData to '\0' you are manipulating the pointer, not the data it contains. cData is set to null, and that is what you try to delete (and it always succeeds.) Doesn't the DLL supply an API for freeing this string? IMHO dll's should always be designed that way.

    home

    S Offline
    S Offline
    Shivanand Gupta
    wrote on last edited by
    #21

    if we use delete without using '\0' then problem occur about heap at run time.

    N 1 Reply Last reply
    0
    • S Shivanand Gupta

      if we use delete without using '\0' then problem occur about heap at run time.

      N Offline
      N Offline
      Niklas L
      wrote on last edited by
      #22

      Well, setting it to '\0' is the same as setting it to NULL. In either case, it makes the delete call a no-op, and that's why you don't get a crash, but you DO get a memory leak.

      home

      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