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

  • Home
  • SEARCH
  • 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 4604452
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:17:52+00:00 2026-05-22T00:17:52+00:00

In the following code block, I create a pointer to a struct so I

  • 0

In the following code block, I create a pointer to a struct so I can supply multiple variables to a gtk signal handler, which is set to automatically g_free() the struct when the handler is disconnected.

The second part mallocs the variable again and sends the new pointer to the new signal handler. Will this work?

Just from reading it I presume it will leave the first struct data in place at the pointer, and create a new pointer I can change the data in later, all while properly disposing of the memory later.

Knowing that malloc is hardly so simple, I’m wondering if there is something I’m missing, or should take into account.

signaldata * s;
s = (signaldata *) g_malloc(sizeof(signaldata *));
s->col = 0; s->secondaryCol = -1; s->model = GTK_TREE_MODEL(itemModel);
g_signal_connect_data(firstWidget,"edited",(GCallback) treeview_text_edited,s, (GClosureNotify) g_free, 0);

s = (signaldata *) g_malloc(sizeof(signaldata *));
s->col = 1; s->secondaryCol = -1; s->model = GTK_TREE_MODEL(itemModel);
g_signal_connect_data(secondWidget,"edited",(GCallback) treeview_text_edited,s, (GClosureNotify) g_free, 0);
  • 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-22T00:17:53+00:00Added an answer on May 22, 2026 at 12:17 am

    It should be OK because the pointer itself is copied before calling g_signal_connect_data, so it doesn’t matter that later you assign it a new address by doing a second g_malloc.

    However, you lose your only reference to the first g_malloc‘d memory (unless somehow it becomes accessible from firstWidget) and that can be undesirable if you want to do any further manual manipulation to it.

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

Sidebar

Related Questions

I have following Code Block Which I tried to optimize in the Optimized section
I am trying to create some dynamic sql using the following code block firstSqlStatement
Any suggestions on how I can cleanup the following code pattern that repeats multiple
I have the following code block in my xslt; <xsl:when test=StatusData/Status/Temperature > 27> <td
For the following block of code: For I = 0 To listOfStrings.Count - 1
I need to solve the following question which i can't get to work by
I have several blocks of the following code that each use there own matrix.
Following code, when compiled and run with g++, prints '1' twice, whereas I expect
The following code works great in IE, but not in FF or Safari. I
The following code doesn't compile with gcc, but does with Visual Studio: template <typename

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.