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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:18:38+00:00 2026-05-28T04:18:38+00:00

I have an application which is used to modify content of a pdf file.

  • 0

I have an application which is used to modify content of a pdf file. Once the required changes are made , i save the file and quit the application. During this process i would like the clear the memory that has been assigned to the pdf file. The code is as given below:

    for (i32 i = 0; i < job_state->PDF_IList_len; i++) {
        if(IList[i].PIL_ImageData.PDH_DataPtr.PDH_PathName)
            free (IList[i].PIL_ImageData.PDH_DataPtr.PDH_PathName);
        if(IList[i].PIL_DependentImages)
            free (IList[i].PIL_DependentImages);
    }
    job_state->PDF_ImageList = NULL;
    job_state->PDF_context = NULL;
    free (IList);

job_structure is a data structure to save info about the file.
PDH_Pathname is the temp directory where the details of the pdf is stored.

My application always crashes at

free (IList[i].PIL_ImageData.PDH_DataPtr.PDH_PathName);

I have noticed that whenever it crashes,the value for free (IList[i].PIL_ImageData.PDH_DataPtr.PDH_PathName) cannot be evaluated(thats what the debugger says).

If the for loop is commented out, there is no crash observed. Please let me know what can be the issue.

  • 1 1 Answer
  • 3 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-28T04:18:38+00:00Added an answer on May 28, 2026 at 4:18 am

    In addition to Als’ answer to use valgrind, it’s probably worth setting your pointers to NULL after you’ve freed them:

    for (i32 i = 0; i < job_state->PDF_IList_len; i++) {
        free (IList[i].PIL_ImageData.PDH_DataPtr.PDH_PathName);
        IList[i].PIL_ImageData.PDH_DataPtr.PDH_PathName = NULL;
        free (IList[i].PIL_DependentImages);
        IList[i].PIL_ImageData.PDH_DataPtr.PDH_PathName = NULL;        
    }
    

    free() doesn’t set pointers to NULL, it only releases the memory stored there. Since you’re testing the value of the pointer against zero to determine whether it needs to be freed, not setting the pointers to NULL could be causing a double free if this code is called twice (or if anything inside IList[] points to a structure also encountered later in the IList[]).

    As per a comment, I’ve also removed the check against NULL before the free (as Joshua Green points out, free(NULL) is perfectly safe).

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

Sidebar

Related Questions

We have a Server/Client cybercafe management application which used to work fine on Windows
I have a number of enums in my application which are used as property
The problem: we have one application that has a portion which is used by
I have a windows service application which works using remoting. It is used to
In my c# application i have this small form which is used to set
I am migrating application from JSF1.2/MyFaces+Facelets TO JSF2.1/MyFaces. I have following template which used
I have to create a DLL which is used by a VB6 application. This
In Application i have two buttons in which one button is used as a
I have a C++ application which used Mutex, Events,Semaphores for synchronization. While hosted in
I have a simple Windows Forms application which is used to calculate the solutions

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.