Index: kernel/generic/src/udebug/udebug_ops.c
===================================================================
--- kernel/generic/src/udebug/udebug_ops.c	(revision 7ec3c5638215716bb0cffafe64b4b0bdc6a543b3)
+++ kernel/generic/src/udebug/udebug_ops.c	(revision 4d11204a6f45850dfd155527e40dd9bf4c7b7bef)
@@ -375,4 +375,5 @@
 	if (TASK->udebug.dt_state != UDEBUG_TS_ACTIVE) {
 		mutex_unlock(&TASK->udebug.lock);
+		free(id_buffer);
 		return EINVAL;
 	}
@@ -456,7 +457,4 @@
 int udebug_args_read(thread_t *thread, void **buffer)
 {
-	/* Prepare a buffer to hold the arguments. */
-	sysarg_t *arg_buffer = malloc(6 * sizeof(sysarg_t), 0);
-	
 	/* On success, this will lock t->udebug.lock. */
 	int rc = _thread_op_begin(thread, false);
@@ -471,4 +469,7 @@
 	}
 	
+	/* Prepare a buffer to hold the arguments. */
+	sysarg_t *arg_buffer = malloc(6 * sizeof(sysarg_t), 0);
+	
 	/* Copy to a local buffer before releasing the lock. */
 	memcpy(arg_buffer, thread->udebug.syscall_args, 6 * sizeof(sysarg_t));
@@ -499,7 +500,4 @@
 int udebug_regs_read(thread_t *thread, void **buffer)
 {
-	/* Prepare a buffer to hold the data. */
-	istate_t *state_buf = malloc(sizeof(istate_t), 0);
-	
 	/* On success, this will lock t->udebug.lock */
 	int rc = _thread_op_begin(thread, false);
@@ -512,4 +510,7 @@
 		return EBUSY;
 	}
+	
+	/* Prepare a buffer to hold the data. */
+	istate_t *state_buf = malloc(sizeof(istate_t), 0);
 	
 	/* Copy to the allocated buffer */
