memory leak fix

call free on different parts of dbus impementation
This commit is contained in:
Jonathan Santis 2024-10-28 11:00:13 +01:00
parent f3c95bcb69
commit d1618bf066

20
main.c
View File

@ -51,6 +51,7 @@ int main(int argc,char *argv[])
char path[256]; char path[256];
time = clock(); time = clock();
curl_global_init(CURL_GLOBAL_DEFAULT);
printf("time:%f\n",(float)time / CLOCKS_PER_SEC); printf("time:%f\n",(float)time / CLOCKS_PER_SEC);
@ -59,6 +60,7 @@ int main(int argc,char *argv[])
if(dbus_error_is_set(&error)) if(dbus_error_is_set(&error))
{ {
fprintf(stderr,"%s",error.message); fprintf(stderr,"%s",error.message);
dbus_error_free(&error);
return -1; return -1;
} }
printf("This is my unique dbus name: %s\n",dbus_bus_get_unique_name(connection)); printf("This is my unique dbus name: %s\n",dbus_bus_get_unique_name(connection));
@ -159,6 +161,7 @@ int main(int argc,char *argv[])
{ {
fprintf(stderr,HELP_TEXT); fprintf(stderr,HELP_TEXT);
} }
curl_global_cleanup();
return 0; return 0;
} }
int getPath(char *configPath,int size) int getPath(char *configPath,int size)
@ -182,6 +185,7 @@ int DBusOptions(DBusConnection *connection,DBusError **error) //not tested check
if(dbus_error_is_set(*error)) if(dbus_error_is_set(*error))
{ {
fprintf(stderr,"%s",(**error).message); fprintf(stderr,"%s",(**error).message);
dbus_error_free(*error);
return -1; return -1;
}else }else
{ {
@ -273,7 +277,7 @@ int gotify_message(char *url,char *title,char *message)
char post_buffer[128]; char post_buffer[128];
char url_buffer[128]; char url_buffer[128];
long response_code; long response_code;
curl = curl_easy_init(); curl = curl_easy_init();
const char* token = NULL; const char* token = NULL;
@ -328,7 +332,7 @@ int gotify_message(char *url,char *title,char *message)
{ {
printf("Error on string concelblalbla: %d\n",ret); printf("Error on string concelblalbla: %d\n",ret);
} }
curl_easy_cleanup(curl);
return 0; return 0;
} }
@ -430,6 +434,7 @@ int systemdCall(DBusConnection *connection,char *method,char *param)
if(dbus_error_is_set(&error)) if(dbus_error_is_set(&error))
{ {
fprintf(stderr,"%s\n",error.message); fprintf(stderr,"%s\n",error.message);
dbus_error_free(&error);
return -1; return -1;
} }
return 0; return 0;
@ -456,6 +461,7 @@ int systemdUnitCall(DBusConnection *connection,char *target,char *method,char *p
if(NULL == msg) if(NULL == msg)
{ {
fprintf(stderr,"Message null, no message created\n"); fprintf(stderr,"Message null, no message created\n");
dbus_message_unref(msg);
return 1; return 1;
} }
@ -465,11 +471,13 @@ int systemdUnitCall(DBusConnection *connection,char *target,char *method,char *p
if(!dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&param2)) if(!dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&param2))
{ {
fprintf(stderr,"Error appending\n"); fprintf(stderr,"Error appending\n");
dbus_message_unref(msg);
return -1; return -1;
} }
if(!dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&param)) if(!dbus_message_iter_append_basic(&iter,DBUS_TYPE_STRING,&param))
{ {
fprintf(stderr,"Error appending\n"); fprintf(stderr,"Error appending\n");
dbus_message_unref(msg);
return -1; return -1;
} }
} }
@ -478,6 +486,8 @@ int systemdUnitCall(DBusConnection *connection,char *target,char *method,char *p
if(ret_msg == NULL) if(ret_msg == NULL)
{ {
fprintf(stderr,"error ond receiving message from peer\n"); fprintf(stderr,"error ond receiving message from peer\n");
dbus_message_unref(msg);
dbus_message_unref(ret_msg);
return 1; return 1;
} }
else else
@ -511,6 +521,7 @@ int systemdUnitCall(DBusConnection *connection,char *target,char *method,char *p
dbus_message_iter_get_basic(&variant_iter,result); dbus_message_iter_get_basic(&variant_iter,result);
//printf("*result:%s\n",*result); //printf("*result:%s\n",*result);
} }
dbus_free(type);
} }
if(ret1 == DBUS_TYPE_ARRAY) if(ret1 == DBUS_TYPE_ARRAY)
{ {
@ -542,8 +553,13 @@ int systemdUnitCall(DBusConnection *connection,char *target,char *method,char *p
if(dbus_error_is_set(&error)) if(dbus_error_is_set(&error))
{ {
fprintf(stderr,"%s\n",error.message); fprintf(stderr,"%s\n",error.message);
dbus_error_free(&error);
dbus_message_unref(msg);
dbus_message_unref(ret_msg);
return 1; return 1;
} }
dbus_message_unref(msg);
dbus_message_unref(ret_msg);
return 0; return 0;
} }