Browse Source

Fix potential memory leak

Serj Kalichev 10 years ago
parent
commit
10d83e099b
1 changed files with 7 additions and 1 deletions
  1. 7 1
      clish/shell/shell_xml.c

+ 7 - 1
clish/shell/shell_xml.c

@@ -417,7 +417,13 @@ static int process_overview(clish_shell_t *shell, clish_xmlnode_t *element,
 	 * Ergo, it -should- be safe.
 	 */
 	do {
-		content = (char*)realloc(content, content_len);
+		char *new = (char*)realloc(content, content_len);
+		if (!new) {
+			if (content)
+				free(content);
+			return -1;
+		}
+		content = new;
 		result = clish_xmlnode_get_content(element, content,
 			&content_len);
 	} while (result == -E2BIG);