Fix return value handling for libustcmd
authorDavid Goulet <david.goulet@polymtl.ca>
Tue, 7 Sep 2010 20:26:12 +0000 (22:26 +0200)
committerNils Carlson <nils.carlson@ericsson.com>
Thu, 9 Sep 2010 15:38:19 +0000 (17:38 +0200)
Return value was not checked correctly so this was
triggering a free() on an invalid pointer causing
ustctl to fail badly.

Signed-off-by: David Goulet <david.goulet@polymtl.ca>
libustcmd/ustcmd.c

index 5b4fd02efcf242854e9ed69a6455a6ede087ac4e..f0a6ae0a25059cfcaead24f313c0b926e5ccb02a 100644 (file)
@@ -97,7 +97,7 @@ int ustcmd_set_marker_state(const char *mn, int state, pid_t pid)
        }
 
        result = ustcmd_send_cmd(cmd, pid, NULL);
-       if (result) {
+       if (result != 1) {
                free(cmd);
                return USTCMD_ERR_GEN;
        }
@@ -182,9 +182,8 @@ int ustcmd_get_subbuf_size(const char *channel, pid_t pid)
        }
 
        result = ustcmd_send_cmd(cmd, pid, &reply);
-       if (result) {
+       if (result != 1) {
                free(cmd);
-               free(reply);
                return -1;
        }
 
@@ -214,9 +213,8 @@ int ustcmd_get_subbuf_num(const char *channel, pid_t pid)
        }
 
        result = ustcmd_send_cmd(cmd, pid, &reply);
-       if (result) {
+       if (result != 1) {
                free(cmd);
-               free(reply);
                return -1;
        }
 
@@ -488,7 +486,6 @@ int ustcmd_get_sock_path(char **sock_path, pid_t pid)
        result = ustcmd_send_cmd(cmd, pid, &reply);
        if (result != 1) {
                free(cmd);
-               free(reply);
                return USTCMD_ERR_GEN;
        }
 
@@ -516,7 +513,7 @@ int ustcmd_force_switch(pid_t pid)
  * @param pid  Targeted PID
  * @param reply        Pointer to string to be filled with a reply string (must
  *             be NULL if no reply is needed for the given command).
- * @return     -1 if successful, 0 on EOT, 1 on success
+ * @return     -1 if not successful, 0 on EOT, 1 on success
  */
 
 int ustcmd_send_cmd(const char *cmd, const pid_t pid, char **reply)
This page took 0.024619 seconds and 4 git commands to generate.