Forum

Results 1 to 9 of 9
  1. #1
    Join Date
    September 2005
    Location
    Germany / Dortmund
    Posts
    1,376

    Memory management of PluginBookmarkList

    Does anybody know the right usage of PluginBookmarkList/getBookmarkList?
    If I call it, I'll get correct results. What I don't understand, is how to cleanup the memory after that.

    If I simply call freeMemory on the pointer, the client crashes. If I don't call it, the client will crash on unloading the plugin.
    I already tested, calling freeMemory on each "child" item first, but had no luck with it.

    Here is some snippet:
    Code:
    PluginBookmarkList* bookmarks;
    
      if (funcs.getBookmarkList(&bookmarks) == ERROR_ok) {
        for (int i = 0; i < bookmarks->itemcount; ++i)
          printf("got bm %s\n", bookmarks->items[i].name);
    
    
        printf("I'll print this\n");
        funcs.freeMemory(bookmarks);
        printf("but not this\n");
      }
    Or is this a bug?

    Running on linux amd64 here.

  2. #2
    Join Date
    September 2012
    Posts
    6,080
    That's currently a bug due to changes for the new client.
    On Windows you won't even get that far and crash directly in the function call (at least with your code).
    Once fixed, to release allocated memory you will have to call freeMemory for the main pointer and the folder member of each item where isFolder is true.

    Thanks for report.
    Last edited by Chris; January 24th, 2017 at 02:50 PM.
    When sending PMs please make sure to include a reference link to the thread in question in the body of your message.

  3. #3
    Join Date
    September 2005
    Location
    Germany / Dortmund
    Posts
    1,376
    Thx for the quick reply!

  4. #4
    Join Date
    September 2012
    Posts
    6,080
    Will be fixed with next client.
    Developers reminded me you also have to free the char* members of the struct, which I forgot when I was testing it and wrote the reply.
    When sending PMs please make sure to include a reference link to the thread in question in the body of your message.

  5. #5
    Join Date
    September 2005
    Location
    Germany / Dortmund
    Posts
    1,376
    So something like this:
    Code:
    void freeBookmarkList(struct PluginBookmarkList* list) {
      for (int i = 0; i < list->itemcount; ++i) {
        ts3_funcs.freeMemory(list->items[i].name);
        if (list->items[i].isFolder)
          freeBookmarkList(list->items[i].folder);
        else ts3_funcs.freeMemory(list->items[i].uuid); //or does directories also have a uuid?
      }
    
      ts3_funcs.freeMemory(list);
    }

  6. #6
    Join Date
    September 2012
    Posts
    6,080
    Quote Originally Posted by Thomas View Post
    So something like this:
    Code:
    void freeBookmarkList(struct PluginBookmarkList* list) {
      for (int i = 0; i < list->itemcount; ++i) {
        ts3_funcs.freeMemory(list->items[i].name);
        if (list->items[i].isFolder)
          freeBookmarkList(list->items[i].folder);
        else ts3_funcs.freeMemory(list->items[i].uuid); //or does directories also have a uuid?
      }
    
      ts3_funcs.freeMemory(list);
    }
    Yes, like that.
    There will be an example in the plugin.c with the next update.
    When sending PMs please make sure to include a reference link to the thread in question in the body of your message.

  7. #7
    Join Date
    September 2005
    Location
    Germany / Dortmund
    Posts
    1,376
    I'll post it here, because it could be related.

    If you try to create a bookmark (createBookmark), what is the purpose of the first parameter (bookmarkuuid)? I could imagine it should be either the predecessor in list or the parent folder of the new bookmark.
    If I pass a valid uuid of an existing bookmark, there is no new bookmark (but the function returns 0).
    If I pass an empty string, the bookmark is created. Don't know if the position in list is random.

    Follow up: Folders does not seem to have a uuid, so how do you create a bookmark as child of a folder?

  8. #8
    Join Date
    September 2012
    Posts
    6,080
    The uuid parameter should be nullptr, it is marked for removal.
    You cannot specify the position of the bookmark that is being created. The user has the choice of where to put it after it was created. It will be created according to the users options and is (should) always be created at the end of the list.
    Before you ask: No you cannot create Folders either.
    When sending PMs please make sure to include a reference link to the thread in question in the body of your message.

  9. #9
    Join Date
    September 2005
    Location
    Germany / Dortmund
    Posts
    1,376
    Thx, all questions asked (for now ).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. I need Help with my password management
    By brian7295 in forum General Questions
    Replies: 1
    Last Post: July 14th, 2011, 10:52 AM
  2. TS3 Rights Management
    By Juzaa in forum Suggestions and Feedback
    Replies: 5
    Last Post: May 18th, 2010, 10:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •