On Fri, Sep 21, 2018 at 10:46:13AM +0100, Stuart Henderson wrote:
> Same problem exists, get_apm_adapter() allocates itself and returns
> a pointer to that memory, so now you're allocating yourself, throwing
> away the address, freeing the memory allocated by get_apm_adapter(),
> and leaking the memory from your calloc.
>
> Try something along these lines:
>
> char *apm_status;
> apm_status = get_apm_adapter();
> if (apm_status != NULL) {
> if (strcmp(apm_status,"off-line") == 0) {
> update_interval = update_interval_bat;
> else
> update_interval = update_interval_old;
> free(apm_status);
> }
>
>
>
>
> > +#endif
> > }
> > info.looped++;
Hi,
You're absolutely right. I re-checked get_apm_adapter() and it
left that bit of memory allocated without freeing it. There's only
one other bit in the code that calls it and it too frees the pointer.
(My C is very very rusty -- I'm kind of re-learning it after 25
years!)
Here's the updated diff below. Thanks for your guidance and
patience with me, Stuart. :)
-Tom
Index: Makefile
===================================================================
RCS file: /cvs/ports/sysutils/conky/Makefile,v
retrieving revision 1.54
diff -u -p -u -p -r1.54 Makefile
--- Makefile 1 Jun 2018 14:24:55 -0000 1.54
+++ Makefile 23 Sep 2018 10:09:16 -0000
@@ -7,7 +7,7 @@ COMMENT= light-weight system monitor
DISTNAME= conky-1.9.0
CATEGORIES= sysutils
HOMEPAGE= http://conky.sourceforge.net/
-REVISION= 15
+REVISION= 16
MASTER_SITES= ${MASTER_SITE_SOURCEFORGE:=conky/}
Index: patches/patch-src_conky_c
===================================================================
RCS file: /cvs/ports/sysutils/conky/patches/patch-src_conky_c,v
retrieving revision 1.6
diff -u -p -u -p -r1.6 patch-src_conky_c
--- patches/patch-src_conky_c 31 Dec 2012 09:36:38 -0000 1.6
+++ patches/patch-src_conky_c 23 Sep 2018 10:09:16 -0000
@@ -1,6 +1,11 @@
$OpenBSD: patch-src_conky_c,v 1.6 2012/12/31 09:36:38 chrisz Exp $
---- src/conky.c.orig Thu May 3 23:22:21 2012
-+++ src/conky.c Tue Jul 24 18:10:39 2012
+
+Correctly change update_interval based on whether AC is plugged in
+or on battery for OpenBSD.
+
+Index: src/conky.c
+--- src/conky.c.orig
++++ src/conky.c
@@ -125,7 +125,7 @@
/* FIXME: apm_getinfo is unused here. maybe it's meant for common.c */
@@ -39,17 +44,31 @@ $OpenBSD: patch-src_conky_c,v 1.6 2012/1
OBJ(apm_adapter) {
char *msg;
-@@ -3496,12 +3492,14 @@ static void main_loop(void)
+@@ -3494,14 +3490,27 @@ static void main_loop(void)
+ info.looped = 0;
+ while (terminate == 0 && (total_run_times == 0 || info.looped <
total_run_times)) {
if(update_interval_bat != NOBATTERY && update_interval_bat !=
update_interval_old) {
- char buf[max_user_text];
+- char buf[max_user_text];
+#ifndef __OpenBSD__
++ char buf[max_user_text];
get_battery_short_status(buf, max_user_text, "BAT0");
if(buf[0] == 'D') {
update_interval = update_interval_bat;
} else {
update_interval = update_interval_old;
}
++#else
++ char *apm_status;
++ apm_status = get_apm_adapter();
++ if (apm_status != NULL) {
++ if (strcmp(apm_status,"off-line") == 0) {
++ update_interval = update_interval_bat;
++ } else {
++ update_interval = update_interval_old;
++ }
++ free(apm_status);
++ }
+#endif
}
info.looped++;