Skip to content

Commit

Permalink
Fix memory leaks in cpdbGetOptionTranslation etc. (#77)
Browse files Browse the repository at this point in the history
`print_backend_call_get_option_translation_sync` calls
`g_variant_get`, which already allocates a new string
for `translation`, so there's no need to call `g_strdup`
again.

Same for `cpdbGetChoiceTranslation` and `cpdbGetGroupTranslation`.

This fixes memory leaks seen e.g. with cpdb-text-frontend
when using commands like these ones to print translation
for options of the CUPS-PDF printer:

    > get-option-translation output-bin PDF CUPS
    Output Tray
    > get-choice-translation output-bin face-down PDF CUPS
    Face Down

Corresponding valgrind output:

    ==298753== 12 bytes in 1 blocks are definitely lost in loss record 55 of 1,289
    ==298753==    at 0x4843808: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==298753==    by 0x4916B81: g_malloc (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.8200.1)
    ==298753==    by 0x49334E2: g_strdup (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.8200.1)
    ==298753==    by 0x495BE61: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.8200.1)
    ==298753==    by 0x495BAEF: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.8200.1)
    ==298753==    by 0x495CC7D: g_variant_get_va (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.8200.1)
    ==298753==    by 0x495CEF2: g_variant_get (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.8200.1)
    ==298753==    by 0x486FFB3: print_backend_call_get_option_translation_sync (backend-interface.c:3337)
    ==298753==    by 0x485D843: cpdbGetOptionTranslation (cpdb-frontend.c:1486)
    ==298753==    by 0x10BA4D: control_thread (cpdb-text-frontend.c:452)
    ==298753==    by 0x4940160: ??? (in /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.8200.1)
    ==298753==    by 0x4A95111: start_thread (pthread_create.c:447)
    ==298753==    by 0x4B1372F: clone (clone.S:100)
  • Loading branch information
michaelweghorn authored Oct 15, 2024
1 parent e942daf commit 5a43d6c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cpdb/cpdb-frontend.c
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,7 @@ char *cpdbGetOptionTranslation(cpdb_printer_obj_t *p,

logdebug("Obtained translation=%s; for option=%s;locale=%s;printer=%s#%s;\n",
translation, option_name, locale, p->id, p->backend_name);
return g_strdup(translation);
return translation;
}

char *cpdbGetChoiceTranslation(cpdb_printer_obj_t *p,
Expand Down Expand Up @@ -1553,7 +1553,7 @@ char *cpdbGetChoiceTranslation(cpdb_printer_obj_t *p,
logdebug("Obtained translation=%s; for option=%s;choice=%s;locale=%s;printer=%s#%s;\n",
translation, option_name, choice_name, locale,
p->id, p->backend_name);
return g_strdup(translation);
return translation;
}


Expand Down Expand Up @@ -1601,7 +1601,7 @@ char *cpdbGetGroupTranslation(cpdb_printer_obj_t *p,

logdebug("Obtained translation=%s; for group=%s;locale=%s;printer=%s#%s;\n",
translation, group_name, locale, p->id, p->backend_name);
return g_strdup(translation);
return translation;
}

void cpdbGetAllTranslations(cpdb_printer_obj_t *p,
Expand Down

0 comments on commit 5a43d6c

Please sign in to comment.